I have a custom taxonomy and a custom post type. I'm aiming for the following permalink structure:
{custom taxonomy}/{custom taxonomy term}/{custom post slug}
Or, at the very least,
{custom taxonomy term}/{custom post slug}
I currently have
{%category%}/{%postname%}
, but no dice.
For example, assume I have:
- a taxonomy
states
, and a taxonomy termnewyork
- a custom post type
jobs
with a post that has the slugwordpress-developer
I am looking to achieve:
states/newyork
: an archive of all thejobs
innewyork
, this works.states/newyork/wordpress-developer
: the custom post's page using the taxonomy & term as the base in the permalink.
The goal is to navigate from states/newyork
(list of "jobs" and flow into the individual post w/o deviating from the permalink structure thus far, so states/newyork/wordpress-developer
Problems encountered:
states/newyork/wordpress
yields a404
newyork/wordpress-developer
redirects tojobs/wordpress-developer
Desired outcome:
states/newyork/wordpress-developer
landing on the custom post type page
PS - not building another job board, just using this as an example :)
current taxonomy & post type register hook:
function register() {
register_taxonomy('state', 'district', array(
'labels' => array(
'name' => 'States',
'singular_name' => 'State',
'search_items' => 'Search States',
'all_items' => 'All States',
'parent_item' => 'Parent State',
'parent_item_colon' => 'Parent State:',
'edit_item' => 'Edit State',
'update_item' => 'Update State',
'add_new_item' => 'Add New State',
'new_item_name' => 'New State',
'menu_name' => 'States'
),
'public' => true,
'show_admin_column' => true,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'states',
'with_front' => false
)
));
register_post_type('district',
array(
'labels' => array(
'name' => 'Districts',
'singular_name' => 'Districts'
),
'hierarchical' => true,
'supports' => array('title', 'page-attributes'),
'public' => true,
'has_archive' => 'states',
'rewrite' => array(
'with_front' => false,
'slug' => 'states/%show_category%'
)
)
);
}
404
post
type.$wp_query
object on the404
template. Therequest
property appears to not identify the custom post type:SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_name = 'district-1' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC