WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my Wordpress permalink settings I have set the Tag-Base to "". So /tag/whatever is the current-url structure for my tag-page.

However I do have a custom-post-type with a custom-taxonomy that is also using this as rewrite_slug.

            'label' => 'Tags',
            'singular_label' => 'Tag',
            'hierarchical' => false,
            'query_var' => true,
            'rewrite' => array('slug' => 'tag'),

This means both (tags for normal posts and tags for my custom-post-type) should have the same permalink structure for their tags.

However this does not work. When I do set the rewrite-slug for my custom-taxonomy to "tag" as well, the normal tag-archive for blogposts throws a 404.

I know I could easily fix this by just using two different rewrite-bases for both post-types. However I wonder if it is possible to make this work as well. So that normal tags of blogposts and tags of my custom-post-type do have the same rewrite structure.

Any ideas on that?

share|improve this question
up vote 0 down vote accepted

If you hook into the 'rewrite_rules_array' filter, do a print_r on $rules, and you'll see the huge preg-match key-value pairs.

add_filter( 'rewrite_rules_array','mess_with_rewrite_rules' );
function mess_with_rewrite_rules( $rules ) {
    return $rules;

See where your rule is in the stack. WordPress loops through this list looking for anything that matches the keys, which are regex patterns, and applies the captured values to the associated value via a preg_match(). I don't know for sure, but I suspect that on the first match, it stops looking. So if tags in the post_tag sense, it stops looking. Thats probably why its not reaching yours.

If im wrong, then it means WordPress doesnt stop looking, but I doubt thats the case. Since the tag doesnt exist in your post_tag taxonomy, it returns a 404. Try setting up a term in post_tags with the same slug and see if you end up landing on that term.

I dont think theres a way to do what your asking. The only way WordPress can know what your looking for via the URI is the pattern of the permalink. If you've got two things with the same pattern, then there is no information to differentiate the two.

Solution A: Use a hierarchical taxonomy instead. Turn tags into a hierarchical taxonomy which can house both sets of terms. The primary problem I suspect would then be the user interface. By making post_tags hierarchical, the metabox will switch to the category-style checkbox list. If you want to maintain the non-hierarchical tag structure, you'll probably need create a custom metabox to only contain children of 'event_tags' and another for all the others.

Solution B: Change something about your 'event_tags' pattern. For example you could for example, have /tag/events/. Then you would insert a special pattern to look for /tag/events/(.+?)$%i. By inserting this at the top of the rewrite rules array, it will match first and stop looking. You can then apply the matched term to index.php?taxonomy=event_tags&term_slug=$matches[1] This would work, however it would break any post_tag whose slug happened to be 'events'.

Note: I don't know if term_slug is the correct query variable, I'm sort of guessing. Look that up by looking at the rewrite rules array, and finding an example of other uses of custom taxonomies.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.