第一register your taxonomy 并设置slug
的参数rewrite
到shows
:
register_taxonomy(
\'show_category\',
\'show\',
array(
\'rewrite\' => array( \'slug\' => \'shows\', \'with_front\' => false ),
// your other args...
)
);
接下来,
register your post type 并将slug设置为
shows/%show_category%
, 和设置
has_archive
参数到
shows
:
register_post_type(
\'show\',
array(
\'rewrite\' => array( \'slug\' => \'shows/%show_category%\', \'with_front\' => false ),
\'has_archive\' => \'shows\',
// your other args...
)
);
最后,将筛选器添加到
post_type_link
要替换单个show permalinks中的show类别,请执行以下操作:
function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == \'show\' ){
$terms = wp_get_object_terms( $post->ID, \'show_category\' );
if( $terms ){
return str_replace( \'%show_category%\' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( \'post_type_link\', \'wpa_show_permalinks\', 1, 2 );
EDIT
忘记了
has_archive
的参数
register_post_type
应设置为
shows
.