当前位置: 动力学知识库 > 问答 > 编程问答 >

wordpress - Register Taxonomy - make regular pages not found

问题描述:

I register new CPT and Taxomony for it, and I want to make URL be like the taxomony

So I look around and come with this code,

everything working with the CPT pages, but regular wordpress pages & posts give me 404 page...

How can I fix that?

 register_taxonomy(

'project_category',

'project',

array(

'rewrite' => array( 'slug' => 'project', 'with_front' => false ),

'hierarchical' => true,

)

);

function project_post_type() {

register_post_type( 'project', array(

'labels' => array(

'name' => 'פרויקטים',

'singular_name' => 'project',

),

'description' => 'פרויקטים',

'public' => true,

'menu_position' => 5,

'supports' => array('title', 'editor', 'thumbnail'),

'menu_icon' => 'dashicons-clipboard',

'rewrite' => array( 'slug' => '%project_category%', 'with_front' => false ),

'has_archive' => 'projects',

));

}

add_action('init', 'project_post_type');

//flush_rewrite_rules(); // I tried without this line and with - and not change

function wpa_show_permalinks( $post_link, $post ){

if ( is_object( $post ) && $post->post_type == 'project' ){

$terms = wp_get_object_terms( $post->ID, 'project_category' );

if( $terms ){

return str_replace( '%project_category%' , $terms[0]->slug , $post_link );

}

}

return $post_link;

}

add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );

分享给朋友:
您可能感兴趣的文章:
随机阅读: