RSS feed with specific keyword

You can modify the list of posts displayed in feed using pre_get_posts action. And to target only feeds, you can use is_feed conditional tag.

So such code can look like this:

add_action( 'pre_get_posts', function ( $query ) {
    if ( ! is_admin() && is_feed() && $query->is_main_query() ) {
        if ( isset($_GET['q']) && trim($_GET['q']) ) {
            $query->set( 's', trim($_GET['q']) );
        }
    }
} );

This way you can go to example.com/feed/?q=KEYWORD and you’ll get filtered feed (be careful – most browsers are caching feeds, so you’ll have to force them to refresh it).

Leave a Comment