• I am trying to display the hierarchy with my CPT and Taxonomy and I can only get one or the other to work. My permalink is displaying correctly but I either get a 404 for the taxonomy page or the post page. I know it can be done because the default WordPress “Categories” works exactly the way I want this to. How can I isolate my rewrite rules so I can get both instead of one or the other?

    $newRules  = array(
    	'cpt-slug/(.+)/(.+)/(.+)/?$' => 'index.php?cpt-slug=$matches[3]',
    	'cpt-slug/(.+)/(.+)/?$'      => 'index.php?cpt-slug=$matches[2]',
    	'cpt-slug/(.+)/?$'           => 'index.php?cpt-slug=$matches[1]',
    	'cpt-slug/?$'                => 'index.php?cpt-slug=$matches[0]',
    	'cpt-slug/(.+)/(.+)/(.+)/?$' => 'index.php?tax-slug=$matches[3]',
    	'cpt-slug/(.+)/(.+)/?$'      => 'index.php?tax-slug=$matches[2]',
    	'cpt-slug/(.+)/?$'           => 'index.php?tax-slug=$matches[1]',
    	'cpt-slug/?$'                => 'index.php?tax-slug=$matches[0]',
    );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    For categories to work the same way, there would be a “category” post type. There is no such thing. If there was, there’d be the same problem. You cannot have two identical regexps and expect the second to ever be used. It would be fundamentally illogical. If code is anything, it must be logical.

    The closest you could get is to go ahead and assume the request is for the CPT, and if the query fails to find anything, then try a query as a taxonomy request instead. Not a very efficient way to do things. If it’s so necessary to have the same slug for both a CPT and taxonomy, then the URL structure of one ought to be somehow different, such as cpt-slug/?$ and tax/cpt-slug/?$

    Thread Starter Carl Brubaker

    (@imconfused4sure)

    Oh, right (duh). Not sure why that didn’t make sense to me before I started this thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CPT and Taxonomy rewrite rules conflict.’ is closed to new replies.