I have a custom post type called resources
which has been registered as so:
register_post_type(
'Resources',
theme_build_post_args(
// $slug, $singular, $plural
'resources', 'Resource', 'Resources',
array(
'menu_position' => 20,
'has_archive' => true,
//'has_archive' => 'types',
'public' => true,
'supports' => array('title', 'revisions', 'thumbnail', 'editor', 'author'),
'taxonomies' => array('topics', 'types', 'industries'),
'rewrite' => array('slug' => 'resources/%types%')
)
)
);
This post type has three taxonomies which have been registered like this:
register_taxonomy(
'topics',
'topics',
array(
'hierarchical' => true,
'label' => 'Topics',
'query_var' => true,
'show_admin_column' => true,
'publicly_queryable' => true,
// 'rewrite' => array('slug' => 'resources')
)
);
register_taxonomy(
'types',
'types',
array(
'hierarchical' => true,
'label' => 'Types',
'query_var' => true,
'show_admin_column' => true,
'publicly_queryable' => true,
// 'rewrite' => array('slug' => 'resources')
)
);
register_taxonomy(
'industries',
'industries',
array(
'hierarchical' => true,
'label' => 'Industry',
'query_var' => true,
'show_admin_column' => true,
'publicly_queryable' => true,
// 'rewrite' => array('slug' => 'resources')
)
);
Currently, when accessing a category defined in any taxonomy, the slug ignores /resources
. For example, I have a type
called Article
. When accessing this page, it sits on /types/article/
when I need it to sit on /resources/types/article/
.
The same applies for topics
and industries
.
Now I have seen approaches stating this should do the trick:
'rewrite' => array('slug' => 'resources/%types%')
However, the above doesn't work for types
, meaning types still do not sit under /resources
, but also, I need this to occur for 3 taxonomies, rather than just 1 and I cannot rewrite
slugs for 3 taxonomies.
How do I go about this?
resources
CPT, or is it the permalink of the terms in your taxonomy? (clicking on a term permalink would bring you to the term's archive which by default displays posts in that term) And for example thetypes
taxonomy, do you want its terms to have the structure/resources/types/<term slug>
(e.g./resources/types/type-one
), or do you want it be/resources/<term slug>
(e.g./resources/type-one
) instead? I.e. No/types
there./resources/types/<term slug>
. For example, If I have atype
called "Article", the structure I'm after is/resources/types/article
. If I have anindustry
called "Accounting" the structure I'm after is/resources/industries/accounting
. Lastly, if I have atopic
called "Security", then the structure I'm after is/resources/topics/security
'rewrite' => array('slug' => 'resources/<taxonomy>')
, e.g.'rewrite' => array('slug' => 'resources/topics')
for thetopics
taxonomy. Have you already tried that?/topics/accounting/
. Also, as mentioned above, I need this implemented for three different taxonomies, not just for one. As far as I can seerewrite
is only possible for one taxonomy?/%postname%/
. I was testing'rewrite' => array('slug' => 'resources/%types%')
just to see if that would maketypes
sit under/resources
and if it was successful, was going to explore how to apply the same for the other 2 taxonomies. However, it didn't achieve what I was after. But, left the code in the demo to showcase what I've tried.