首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何阅读Wordpress Permalink自定义分类为3级?

如何阅读Wordpress Permalink自定义分类为3级?
EN

Stack Overflow用户
提问于 2019-05-16 09:31:20
回答 1查看 49关注 0票数 1

目前,我正在创建一个CPT,它有自己的自定义分类法。可以选择父项和子项。但是当我创建一个新闻帖子时,分类法按层次顺序只选择最后一个子项。

我尝试将层次结构设置为false,将'with_front‘=>更改为false,在like,'rewrite’=>数组上添加了另一个自定义分类(‘slug’=> 'what-we-do/%wwd-category%/%wwd-category%'),但结果类似于‘localhost/CPT/TAYO1/TACO1/=>’,在两个位置重复最后一个子项选择。

代码语言:javascript
复制
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

The order on permalink only shows the last of the taxonomy

The hierarchical is pushing selected taxonomy out-of-order

EN

回答 1

Stack Overflow用户

发布于 2019-05-16 15:15:35

我已经得到了答案,使用名为WP Better Permalinks的Wordpress插件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56159625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档