Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?

You can use add_rewrite_rule hooked to the init action, instead of using the generate_rewrite_rules filter (where it gets a bit low-level).

But the actual problem with your rewrite rules is the regex in place. Here’s what it’d look like:

function wtnerd_edition_specific_categories() {
    add_rewrite_rule( '(.+?)/channel/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]', 'top' );
    add_rewrite_rule( '(.+?)/channel/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]', 'top' );
    add_rewrite_rule( '(.+?)/channel/(.+?)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]&paged=$matches[3]', 'top' );
    add_rewrite_rule( '(.+?)/channel/(.+?)/?$', 'index.php?category_name=$matches[1]&channel=$matches[2]', 'top' );

    add_rewrite_rule( '(.+?)/section/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]', 'top' );
    add_rewrite_rule( '(.+?)/section/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]', 'top' );
    add_rewrite_rule( '(.+?)/section/(.+?)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]&paged=$matches[3]', 'top' );
    add_rewrite_rule( '(.+?)/section/(.+?)/?$', 'index.php?category_name=$matches[1]&tag=$matches[2]', 'top' );
}
add_action( 'init', 'wtnerd_edition_specific_categories' );

You can also use rewrite_rules_array filter hook.

Leave a Comment