Permalink rewriting interference between post type and taxonomy
-
I have a custom post type called “books” that has a permalink structure like /books/post-name
I have a custom taxonomy called “book sets” that contains terms that will organize the books into sets. I want the permalink structure of this taxonomy term archive to be like /books/book-sets/term-name
The taxonomy archive/term URL needs to contain a post-type path as part of it’s path.
However, there is some kind of collision between the post type URL and this taxonomy archive URL. I get a 404 error when I set my taxonomy rewrite slug (in the register taxonomy function) to “books/book-sets”. Everything works fine when I set the taxonomy rewrite slug to “book-sets” or anything not containing “books/”, but that is not the permalink structure I need. At present I have rewriting off, so the URLs just look like /us/?book-sets=fantasy
I found this post, which is exactly the issue I am experienceing: http://clarknikdelpowell.com/blog/the-right-way-to-do-wordpress-custom-taxonomy-rewrites/. But the solution in that post does not work for me.
I’m porting the custom post and taxonomy functionality from previous work from another team. They had set up all the customization and permalinks the way the client wanted, however, on a new host with an updated WP installation, all the permalink customization was broken, so I’m having to rebuild it practically from scratch.
I found this old piece of code:
function fix_taxonomy_archive_collision( $wp_query ) { if ( $wp_query->is_tax && $wp_query->is_post_type_archive ) { $wp_query->is_post_type_archive = false; } } add_action( 'parse_query', 'fix_taxonomy_archive_collision' );It might be a clue as to how the previous developers fixed this issue, but it’s not working currently, and I don’t follow how $wp_query->is_post_type_archive = false; would help the situation.
I’ve tried a simple add_rewrite_rule to see if I could circumvent the interference:
function custom_rewrite_rule() { add_rewrite_rule( '^books/book-sets/([^/]*)$', 'index.php/?book-sets=$matches[1]', 'top' ); } add_action('init', 'custom_rewrite_rule', 10, 0);But it doesn’t even seem to be firing on the target URL. I’m working on a multisite, so I’m not sure if that matters or not.
I’d be grateful if anyone has any ideas!
The topic ‘Permalink rewriting interference between post type and taxonomy’ is closed to new replies.