Question updated.
What I'm trying to do
If I want to display posts (or a feed of posts) that belong to a category AND a custom taxonomy, or a category AND a tag, or a custom taxonomy AND a tag, I can do so using query variables as query strings in URL.
But I want to prettify the URLs first, like so:
example.com/?category_name=main&channel=tech
toexample.com/main/channel/tech/
example.com/?category_name=main&channel=tech&feed=rss2
toexample.com/main/channel/tech/feed/
example.com/?category_name=main&tag=jsyk
toexample.com/main/tag/jsyk/
example.com/?category_name=main&tag=jsyk&feed=rss2
toexample.com/main/tag/jsyk/feed/
Where category_name
defines the category slug, channel
the custom taxonomy "Channel" term's slug, and tag
the tag slug.
How I'm doing it
First, I tried reading as many examples as possible, including:
I place all theme independent functions for my site in a must-use plugin, which looks like this:
<?php
/*
* Plugin Name: Default Functions
* Description: Site-specific functions for example.com
*/
/* Add functions below */
/* THE END */
That's where I added my rewrite function which looks like this:
function wtnerd_edition_specific_categories( $wp_rewrite ) {
$rewrite_rules = array(
'([a-zA-Z0-9-_^/]+)/channel/([a-zA-Z0-9-_^/]+)' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&channel='.$wp_rewrite->preg_index(2),
'([a-zA-Z0-9-_^/]+)/channel/([a-zA-Z0-9-_^/]+)/feed' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&channel='.$wp_rewrite->preg_index(2).'&feed=rss2',
'([a-zA-Z0-9-_^/]+)/section/([a-zA-Z0-9-_^/]+)' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&tag='.$wp_rewrite->preg_index(2),
'([a-zA-Z0-9-_^/]+)/section/([a-zA-Z0-9-_^/]+)/feed' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&tag='.$wp_rewrite->preg_index(2).'&feed=rss2'
);
$wp_rewrite->rules = $rewrite_rules + $wp_rewrite->rules;
}
add_filter( 'generate_rewrite_rules', 'wtnerd_edition_specific_categories' );
Problem
The feed URLs don't work. For example:
example.com/main/channel/tech/feed/
loads the content-none.php
template instead of showing the actual feed of posts that belong to the said terms.
I am not sure how to fix this.