$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - RSS feed with specific keyword|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - RSS feed with specific keyword

matteradmin9PV0评论

I am able to get articles as RSS feed from below url

http://wordpress_site/blog/feed

I am also able to get articles from BlogSpot with specific keywords as below


I have tried to get articles from filtering with specific KEYWORD in wordpress blog but I am not able to get. What can be the URL.

I am very much newbie to wordpress.

I am able to get articles as RSS feed from below url

http://wordpress_site/blog/feed

I am also able to get articles from BlogSpot with specific keywords as below

https://www.yourblogname.blogspot/feeds/posts/default?q=KEYWORD

I have tried to get articles from filtering with specific KEYWORD in wordpress blog but I am not able to get. What can be the URL.

I am very much newbie to wordpress.

Share Improve this question edited Feb 12, 2019 at 8:49 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Feb 12, 2019 at 7:53 Dushyant JoshiDushyant Joshi 1431 silver badge5 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

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/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).

Here's how we can use the builtin public query parameters on feeds:

Query parameter: s

We can use the s query parameter on the feed:

https://example/feed/?s=KEYWORD

This will generate a feed for the keyword on all searchable post types.

Query parameter: post_type

We can restrict it to a given post type with:

https://example/feed/?s=KEYWORD&post_type=post

Query parameter: exact

We can also use the exact query search parameter to exactly match the search keyword (no wildcard):

https://example/feed/?s=hello+world&post_type=post&exact=1

Query parameter: sentence

The sentence query search parameter can be used to match the whole keyword sentence (no word split):

https://example/feed/?s=hello+world&post_type=post&sentence=1

All together:

https://example/feed/?s=hello+world&post_type=post&exact=1&sentence=1

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far