First issue- the permalink structure in Settings is only for the post
post type, so your post_type_link
function has no %types%
tag to replace.
Second- unless you want a very complicated (and less performant) solution, the simpler solution is to have a static prefix in your post type slug. With the URL http://domain.com/type/location/post-name/
, WordPress has no way of knowing what you’re asking for. Is type
a page with child page location
, or is it a types
taxonomy term? Using the standard rewrites system, one rule will always take precedence, and the other requests will always 404. With the URL format http://domain.com/item/type/location/post-name/
, WordPress will know exactly what you’re asking for, because only one post type is prefixed with item
.
As for specifics- in your post type registration, set the slug
argument of rewrite
to the format of URL you want:
'rewrite' => array( 'slug' => 'item/%types%' ),
… and your post_type_link
filter should work. If you want to add locations, just add that tag to the slug and add the code to replace the tag in your post_type_link
filter-
'rewrite' => array( 'slug' => 'item/%types%/%locations%' ),