You commented, “As far as I can see rewrite
is only possible for one taxonomy?“.
So no, that’s not true, it’s possible for every taxonomy. Just remember that each taxonomy should have a unique rewrite slug, so that it does not conflict with other permalinks (for other taxonomies and for post types like post
, page
, etc.). So for instance, if the topics
taxonomy uses topics
as the rewrite slug, then your types
and industries
taxonomies need to use a different rewrite slug. (If you really must use/share the same slug, it’s not impossible, but it’s not in scope of this answer)
Now if these are the permalink structures that you want:
/resources/topics/<term slug>
for thetopics
taxonomy/resources/types/<term slug>
for thetypes
taxonomy/resources/industries/<term slug>
for theindustries
taxonomy
where an example permalink (URL) would look like this:
https://example.com/resources/topics/security/
for a term with the slugsecurity
, in thetopics
taxonomyhttps://example.com/resources/types/article/
for a term with the slugarticle
, in thetypes
taxonomyhttps://example.com/resources/industries/accounting/
for a term with the slugaccounting
, in theindustries
taxonomy
Then just set the rewrite slug for your taxonomy to resources/<taxonomy>
, like so:
(this is the actual code I tried & tested working with WordPress v6.1.1)
function my_register_post_types() {
register_post_type(
'resources', // post type name/slug
array(
'public' => true,
'rewrite' => array( 'slug' => 'resources' ),
'labels' => array(
'name' => 'Resources',
// other labels
),
// other args
)
);
}
function my_register_taxonomies() {
register_taxonomy(
'topics', // taxonomy name/slug
'resources', // attach to this post type
array(
'public' => true,
'rewrite' => array( 'slug' => 'resources/topics' ),
'label' => 'Topics',
'hierarchical' => true,
// other args
)
);
register_taxonomy(
'types', // taxonomy name/slug
'resources', // attach to this post type
array(
'public' => true,
'rewrite' => array( 'slug' => 'resources/types' ),
'label' => 'Types',
'hierarchical' => true,
// other args
)
);
register_taxonomy(
'industries', // taxonomy name/slug
'resources', // attach to this post type
array(
'public' => true,
'rewrite' => array( 'slug' => 'resources/industries' ),
'label' => 'Industries',
'hierarchical' => true,
// other args
)
);
}
However, you need to first register the taxonomies, and only after that, register your resources
post type, if its rewrite slug is resources
, which is the default value, or that the slug starts with resources/
. Otherwise, your term permalinks would result in a 404 error page. :/
// Register the taxonomy first.
add_action( 'init', 'my_register_taxonomies' );
// Then the post type.
add_action( 'init', 'my_register_post_types' );
Also, be sure to flush the rewrite rules (i.e. re-save your permalinks), by simply visiting the Permalink Settings admin page.