注册您的taxonomy 首先,设置参数slug并将规则重写为slug,即city
将您的帖子类型注册到slug
并确保设置has_archive
分类的参数。
现在添加filter 到post_type_link
让商店展示个人的permalink。
register_post_type(
\'city\',
array(
\'rewrite\' => array( \'slug\' => \'city/%stores%\', \'with_front\' => false ),
\'has_archive\' => \'city\',
// additional args
)
);
register_taxonomy(
\'stores\',
\'city\',
array(
\'rewrite\' => array( \'slug\' => \'city\', \'with_front\' => false ),
// your other args...
)
);
function yourprefix_store_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == \'city\' ){
$terms = wp_get_object_terms( $post->ID, \'stores\' );
if( $terms ){
return str_replace( \'%stores%\' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( \'post_type_link\', \'yourprefix_store_permalinks\', 1, 2 );
在此处使用内置工具生成WP内容
GenrateWP希望这就是你要找的。如果不是,你可以阅读类似的文章https://wordpress.stackexchange.com/questions/199456/custom-taxonomy-post-slug-permalink