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).
Related Posts:
- Including only current user’s posts in search
- WP_Query ignoring tax_query when is_singular
- WP_Query – How to get all posts of specific days of week by custom field date?
- Elementor posts custom query based on tag [closed]
- Filter WP_Query output before it is accessed (pre_get_posts)?
- When to use WP_query(), query_posts() and pre_get_posts
- Should I use Pre Get Posts or WP_Query
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Slow SQL_CALC_FOUND_ROWS Query
- Is there an action/filter called when WP_Query->query is finished and assigns posts
- Multiple orderby parameters in pre_get_posts() action
- Sorting Posts by custom field
- Query with pre_get_posts to get pagination
- Recommended way to drop a pending query (in pre_get_posts)?
- Single page theme that uses pages for the content
- Display different number of posts from one category on the different pages
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Which filter/action hook gets triggered after a query has been performed?
- How to sort posts in admin by titles with dd.mm.yyyy format?
- WP_Tax_Query with post_tag not working
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- How to Modify Taxonomy Archive Page with Search Parameter?
- How to display future posts – modified query still yields 404
- pre_get_posts filter meta_query without conflicting existing meta_query
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- How to change posts order on Category and Tag archives?
- Formulate a url to show posts with both taxonomy terms
- My Main Query Modification is Messing up my dynamic main – why?
- Offset Page Loops and Pagination
- pre_get_posts Remove tax_query Completely
- pre_get_posts order by not working
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Store sticky post’s ids in a transient
- Show Sticky Post at the top but do not show again in the loop?
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Show scheduled posts in main loop but not in WP_Query?
- Set global $wp_query/$post variable for dynamic page generation
- hide custom post types with specific meta key ON admin backend
- Applying posts_clauses filter to specific queries only
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- New WP_Query calls Pre_get_posts filter twice
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- Woocommerce – exclude only older out-of-stock items
- pre_get_posts – Trying to get property of non-object warning
- queried_object using pre_get_posts gets notices and warning
- date_query in pre_get_posts out of memory
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- pre_get_posts – editing query, tax_query
- Child pages not affected by orderby
- Get Post ID as a separate RSS feed item
- How to apply pre_get_posts to a custom query?
- tax_query in pre_get_posts
- WP_Query, Paginate by Custom Field
- Exclude post with taxonomy and from the terms (taxonomy & tag) posts count
- `offset` WP_Query argument dont work via `pre_get_posts`
- Block internal search queries with pre_get_posts and regex rules
- is_user_logged_in not working from WP-API (wp-json)
- Search Exact on WordPress – Relevannsi Solution Not Working
- Excluding posts from search results page with meta query not working
- pre_get_posts pagination not working
- meta_query is overriding default search
- pre_user_query vs pre_get_posts
- Can I alter the main loop to ‘orderby’ a custom callback?
- Custom filter from post meta
- How can I re-query post_type and rewrite the url?
- add action for wordpress query at a specific position
- Pre get posts sort by meta key returns no results if meta key does not exist
- Pre_get_posts only show posts by administrator roles
- Modify a query with no results in pre_get_posts
- How order by works?
- Order posts by title and custom field value?
- Custom Order Current Query: By Meta Key and Category
- remove_action – pre_get_posts – does not restore original query
- Limit default Search query to post_title
- why doesn’t this pre_get_posts code work?
- pre_get_posts with WP_Query to prevent posts from specific tags
- Modify query to exclude certain ids and certain parents and its corresponding children
- wp_query – Modify $query to include duplicate content
- Order posts by custom column using pre_get_posts
- pre_get_posts or $where, which one to use?
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- pre_get_posts redirecting
- Avoiding page loop
- Custom post types loop on a page template
- Pre_get_post on CPT archive page
- Search query alteration not working for meta values
- How to put posts with some taxonomy on top of others in `pre_get_posts`