dousi4900 2016-12-14 16:07
浏览 43

Wordpress自定义帖子类型 - URL中的ACF

I have some problem that I need help in them -

I register costum post type - is slug is "project"

But I need to make 3 categories (with ACF) and make url changed due to it

category1 = http://www.example.com/mycaturl/nameoftitle

category2 = http://www.example.com/othercat/nameoftitle

category3 = http://www.example.com/customedit/nameoftitle

How can I make it without plugins...?

Thanks for helpers :)

  • 写回答

1条回答 默认 最新

  • douwen3500 2016-12-14 16:14
    关注

    Tested and verified:

    I am writting in steps to make it clear:

    1. Make sure when you registered your custom post type rewrite for more: register custom post type

    'rewrite' => array('slug' => '/%project_categories%','with_front' => FALSE),

    1. Then register your taxonomies project_categories

    You need to register custom taxonomy project_categories for this custom (project) post type. register_taxonomy please read here for more

    function project_taxonomy() {  
        register_taxonomy(  
            'project_categories',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
            'project',        //post type name
            array(  
                'hierarchical' => true,  
                'label' => 'project store',  //Display name
                'query_var' => true,
                'rewrite' => array(
                    'slug' => 'project', // This controls the base slug that will display before each term
                    'with_front' => false //  Don't display the category base before 
                )
            )  
        );  
    }  
    add_action( 'init', 'project_taxonomy');
    
    1. Last make, your post type liks filters.

      function filter_post_type_link($link, $post)
       {
          if ($post->post_type != 'project')
              return $link;
      
          if ($cats = get_the_terms($post->ID, 'project_categories'))
              $link = str_replace('%project_categories%', array_pop($cats)->slug, $link);
          return $link;
      }
      add_filter('post_type_link', 'filter_post_type_link', 10, 2);
      

    Note: if you see post not found error. then change your permalink settings to default and save changes. And again set permalink to Post name and it will work.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效