Recently I have been working on a WordPress which involved adding a custom post type.Most of you guys know how to create custom post type and for same plugins also available but Do you know how to add custom post type into WordPress RSS feed.
RSS stands for Really Simple Syndication which meant feed and Feed are the easiest way for visitors to subscribe.
In WordPress, It is very easy to add your custom post into Main RSS Feed and for that you need to write some lines of code into your theme’s functions.php file.
Let’s demonstrate code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // Add custom post types to the Main RSS feed if (isset($request['feed']) && !isset($request['post_type'])) : $request['post_type'] = array('post','<custom_post_type1>','<custom_post_type2>'); endif; return $request; } function feed_pre_get_posts($query) { return $query; } add_filter('pre_get_posts', 'feed_pre_get_posts'); |
request filter
is useful to apply with the query variables that are passed to the default main SQL query.so I have used it here which will custom query.Pre_get_posts
is a filter used for altering SQL query.
I think easy enough, right? I’m hoping that you’ve found this article helpful.
Recommended Read:
To use Pagination with Taxonomy in WordPress
Share user Data in multiple WordPress Installation
File/Image Upload in WordPress
As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.