Travis Smith
Travis Smith

Reputation: 538

Custom WordPress Custom Post Type & Custom Taxonomy Rewrite maintaining Default Archives

I have a registered taxonomy (wps_type) and 2 custom post types (wps_business, wps_location) in that order. The registered taxonomy has rewrite arg set to slug => type and the post types have slug => business & slug => location already set. I need a custom smart permalink rewrite rule where all of the following are available.

Defaults Work (and still need to work):

http://domain.com/post-type/post-name => http://domain.com/business/post-name
http://domain.com/post-type/post-name => http://domain.com/location/post-name
http://domain.com/taxonomy/term-name  => http://domain.com/type/term-name

But what I need is:

http://domain.com/post-type/taxonomy  => http://domain.com/location-post-name/type-term-name

So I believe using post_type_link filter may not work, but I could be wrong. Here's some code that I've tried:

add_rewrite_rule( '^directory/([^/]*)/([^/]*)/?', 'index.php?wps_location=$matches[1]&wps_business=$matches[2]', 'top' );
add_rewrite_tag( '%wps_location%', '([^/]+)' );
add_rewrite_tag( '%wps_business_types%', '([^&]+)' );

Upvotes: 1

Views: 482

Answers (1)

chrisjlebron
chrisjlebron

Reputation: 78

Not sure if you ever found your answer, but I just found this article which outlines how to do this (though with a few caveats). Also, not sure if this answer would retain the third permalink structure you mentioned:

http://domain.com/taxonomy/term-name => http://domain.com/type/term-name

I personally rarely find the need for this structure, but often need the http://domain.com/post-type/tax/term structure, so that article works for me.

Upvotes: 0

Related Questions