Permalinks: custom structure for taxonomy – tags?

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 ) {
        print_pre($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.