Permalink rewrite 404 conflict- WordPress Taxonomies/ CPT

You could create verbose page rules for each page that starts with /type/, but you will also need to hook into page creating and stuff like that to keep it up-to-date. If you don’t have that many extra pages, it might be easier to just force verbose page rules for all pages, then WordPress will do this for you.

add_action( 'init', 'wpse16902_init' );
function wpse16902_init() {
    $GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}

The only problem now is that the taxonomy rules are put even on top of that (since WP 3.1 I think). But with the correct hooks we can intercept the page rules and place them really at the top.

add_filter( 'page_rewrite_rules', 'wpse16902_collect_page_rewrite_rules' );
function wpse16902_collect_page_rewrite_rules( $page_rewrite_rules )
{
    $GLOBALS['wpse16902_page_rewrite_rules'] = $page_rewrite_rules;
    return array();
}

add_filter( 'rewrite_rules_array', 'wspe16902_prepend_page_rewrite_rules' );
function wspe16902_prepend_page_rewrite_rules( $rewrite_rules )
{
    return $GLOBALS['wpse16902_page_rewrite_rules'] + $rewrite_rules;
}

It is possible that the rewrite rules for the custom post type and the custom taxonomy collide with each other for the /type/%freshness%/ URLs. You want these to be a taxonomy archive, not a custom post type archive. If you have problems with this, reverse the order in which you register them: first the taxonomy, then the custom post type:

register_taxonomy(
    'freshness',
     array(), // Empty array, no post types linked
     array(
         'rewrite' => array(
             'slug' => 'type',
         )
     ),
 );
 register_post_type(
     'zombie',
     array(
         'rewrite' => array(
             'slug' => 'type/%freshness%',
         ),
         'taxonomies' => array( 'freshness' ),
     ),
 );

Extra notice: if your taxonomy URLs really start with /type/, you might get into conflict with post format archives. /type/aside/ by default displays all posts of the “Aside” format. This answer assumes the zombie custom post type and taxonomy is just an example, and you use another URL format in your real problem.

Leave a Comment