目前,我正在创建一个CPT,它有自己的自定义分类法。可以选择父项和子项。但是当我创建一个新闻帖子时,分类法按层次顺序只选择最后一个子项。
我尝试将层次结构设置为false,将'with_front‘=>更改为false,在like,'rewrite’=>数组上添加了另一个自定义分类(‘slug’=> 'what-we-do/%wwd-category%/%wwd-category%'),但结果类似于‘localhost/CPT/TAYO1/TACO1/=>’,在两个位置重复最后一个子项选择。
function codex_custom_init() {
$args = array(
'public' => true,
'label' => 'What we do',
'has_archive' => 'what-we-do',
'query_var' => true,
'rewrite' => array('slug' => 'what-we-do/%wwd-category%'),
'taxonomies' => array( 'wwd-category' ),
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
);
register_post_type( 'what-we-do', $args );
register_taxonomy(
'wwd-category',
'what-we-do',
array(
'label' => __( 'Categories WWD' ),
'hierarchical' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'what-we-do', 'with-front' => false)
)
);
}
add_action( 'init', 'codex_custom_init' ,1);
function tm_wwd_category_post_link( $post_link, $id = 0 ){
$post = get_post($id);
$terms = wp_get_object_terms( $post->ID, 'wwd-category' );
if( $terms ){
return str_replace( '%wwd-category%' , $terms[0]->slug , $post_link );
} else {
return str_replace( '%wwd-category%/' , '' , $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'tm_wwd_category_post_link', 1, 3 );我目前所取得的成果是
*http:// localhost/CPTUI/custom-taxonomy/postname。
但我想要达到的实际效果是
* localhost/CPTUI/parent/parent-child/child/postname/
感谢您抽出时间来回答这个问题。
Parent-Child level for customtaxonomy
The order before publishing the new post
发布于 2019-05-16 15:15:35
我已经得到了答案,使用名为WP Better Permalinks的Wordpress插件。
https://stackoverflow.com/questions/56159625
复制相似问题