Hi,
I'm developing a plugin with the goal of making it easy to create additional content based on taxonomies on a blog. So, for instance, say a food blog has tags like apples and bananas. These would ordinarily create tag archive pages like example.com/tag/apples and example.com/tag/bananas, etc.
What I'd like to do is create a permalink structure such that a URL like example.com/tag/apples/info produces a page about the apples tag. This page would be a custom post type.
I'm already aware of add_rewrite_endpoint() (I used that feature in this BitTorrent plugin), but what I'm trying to do is more complex.
Using the following combination of Rewrite API calls, I've successfully managed to get URLs like example.com/tag/apples/info to load to the correct page, however, WordPress redirects these pages to their custom post type canonical permalinks, which is like example.com/custom-post-type/apples, and that's not what I want.
The code I have right now looks something like this (simplified for length):
add_rewrite_tag('%custom-post-type%', '(custom-post-type)s', 'post_type=');
add_permastruct('custom_post_type', 'tag/%tag%/info');
add_rewrite_rule('^tag/([^/]+)/info/?', 'index.php?post_type=custom-post-type&pagename=$matches[1]', 'top');
$args = array('rewrite' => array('with_front' => false));
register_post_type(str_replace('_', '-', $this->prefix) . 'page', $args);
flush_rewrite_rules();
Again, this gets URLs like example.com/tag/apples/info to redirect to example.com/custom-post-type/apples, so WordPress is able to find the correct post. But the behavior I want is no redirect.
I tried returning false from the redirect_canonical filter, too, but this just resulted in a 404.
What am I not doing that I need to be doing to get the behavior I want? Also, as a followup question, how can I adjust my code so that a custom tag or category permalink base (other than the default of tag or category) will also be rewritten correctly for my custom post type?
Thanks in advance for your help. :)