I have created a cpt like this:

 register_post_type( 'mission', array(
    'labels'              => array( ... ),
    'supports'            => array( 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'post-formats' ),
    'taxonomies'          => array( 'mission_category', 'mission_client', 'mission_location', 'mission_status'), 
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => 'dashicons-star-filled',
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'post', 

and a custom taxonomy for the cpt above:

 register_taxonomy( 'mission_category', array( 'mission' ), array(
    'public'            => true,
    'show_ui'           => true,
    'show_in_menu'      => true,
    'show_in_nav_menus' => true,
    'show_tagcloud'     => true,
    'show_admin_column' => true,
    'hierarchical'      => true,
    'capabilities' => array(
        'manage_terms' => 'manage_categories',
        'edit_terms'   => 'manage_categories',
        'delete_terms' => 'manage_categories',
        'assign_terms' => 'edit_posts',
    'rewrite' => array(
        'slug'         => 'mission/category',
        'with_front'   => false,
        'hierarchical' => true,
        'ep_mask'      => EP_NONE

I have created two mission_categories named: "Engineering" and "Economy". I expect to find an archive pages at these endpoints: /mission/category/engineering and /mission/category/economy

I also have created two pages with the same name as the categories above. I expect to find these pages at: /engineering and /economy

The strange thing is that when I hace created pages with the same name as my mission_categories, I get redirected to the page when trying to view an archive. That means, if I manually enter this endpoint /mission/category/economy i end up at /economy. Worth mentioning is that the "view-link" from the mission_category page in the admin are correct, but I still get redirected to the page when clicking on it.

This only happens when I have a page with the same name as a category... If I for example remove the economy page, the /mission/category/economy ends up at the correct url.


I found a solution to this by some extensive googling. The key is to declare the taxanomy before the ctp. I have no idea why, but it works =)

source: https://cnpagency.com/blog/the-right-way-to-do-wordpress-custom-taxonomy-rewrites/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.