Restricting the RSS feed to by category, tag, author etc

by Edward on

The RSS Feed method is the default way of making your WordPress articles available so Facebook can import them as Instant Articles. The standard RSS feed WP Native Articles adds, converts all of your posts to instant articles so they can be synced to Facebook. However, it might be that you don’t want all of your articles to be Instant Articles, maybe you only want articles in a certain category? Or by a particular author?

It’s actually fairly simple, because the RSS feed is simply a WP_Query endpoint you can use the pre_get_posts to hook in, check it’s the RSS feed you want then use the standard WP_Query filters to alter the loop as you normally would.

Just add any of the below snippets to your theme’s functions.php file (without the opening PHP tag of course) and alter as you please.

Restricting the RSS Feed by Category

Simply replace the 5 with the ID of whatever category you wish to restrict it to.

Restricting the RSS Feed by Tag

Restricting by tag is pretty similar but this time we’ve used the tag’s slug, just replace it with your own.

Restricting the RSS Feed by Author

Again very similar, just replace 3 with the Author ID you wish to restrict the feed to.

You get the idea. Using the above code you can use any of the WP_Query filters to restrict the RSS feed in whatever way you like.