• Hi guys i have the following code and i am trying to register custom post type with custom taxonomy attached to it which implements a nested permalinks strucutre. Example with the post type blog.

    I want blog posts to be available at mysite.com/blog
    And the custom taxonomies which would be categories at mysite.com/blog/categories. And a few other ones which implement the same structure. The problem is that it works for the CPT, but the taxonomy page returns 404 if it has the parent post type’s slug in its permalink. If i change the taxonomy slug to not use the blog/category structure, but for example to use test/category structure it works. If anyone could help me understand how to properly implement it would be much appreaciated. Thank you

    // # CPT Blog
    function create_post_type_blog() {
    $labels = array(// My custom labels here);

    register_post_type( ‘blog’, array(
    ‘label’ => ‘Публикаци?’,
    ‘labels’ => $labels,
    ‘public’ => true,
    ‘has_archive’ => true,
    ‘supports’ => array ( ‘title’, ‘editor’, ‘thumbnail’, ‘excerpt’ ),
    ‘taxonomies’ => array( ‘blog_categories’, ‘blog_tags’ ),
    ‘rewrite’ => array( ‘slug’ => ‘blog’ )
    )
    );
    }
    add_action( ‘init’, ‘create_post_type_blog’ );

    // # Blog Categories
    function create_blog_categories() {
    $labels = array(// My custom labels here);

    $args = array(
    ‘label’ => ‘Категории’,
    ‘labels’ => $labels,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_admin_column’ => true,
    ‘rewrite’ => array( ‘slug’ => ‘blog/categories’)
    );

    register_taxonomy(‘blog_categories’, ‘blog’, $args);
    }
    add_action( ‘init’, ‘create_blog_categories’ );

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can’t do it that way. The way the regular expressions for the rewrites determine which page to show is there is only one choice for each address. So if you say that /blog is a post type, then /blog/category is a post type of blog with the name of category. The leading part determines how the rest is interpreted.

    Thread Starter ivchodev

    (@ivchodev)

    Yes, I understand. But i am sure its possible to do. Do you know how can i achieve that ?

    If you are so sure, you should figure it out. I just told you that the leading part is what is matched, and everything that follows gives more specifics to that first match. You can’t really nest things given that matching algorithm.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can’t setup nested permalink structure for custom post type’s taxonomies’ is closed to new replies.