To control what post types show up in the default WordPress RSS feed, you can add a function to your themes functions.php
file (if one doesn't exist, create it in your theme folder) to control what is returned when the RSS feed is requested.
function myfeed_request($qv) { // If a request for the RSS feed is made, but the request // isn't specifically for a Custom Post Type feed if (isset($qv['feed']) && !isset($qv['post_type'])) { // Return a feed with posts of post type 'post' $qv['post_type'] = array('post'); } return $qv; } add_filter('request', 'myfeed_request');
If we wanted to modify this so that the default feed includes 'post'
and a entries from Custom Post Type 'thoughts'
, we can modify the function as follows:
function myfeed_request($qv) { // If a request for the RSS feed is made, but the request // isn't specifically for a Custom Post Type feed if (isset($qv['feed']) && !isset($qv['post_type'])) { // Return a feed with posts of post type 'post' and 'thoughts' $qv['post_type'] = array('post', 'thoughts'); } return $qv; } add_filter('request', 'myfeed_request');
Thanks for this. The other solutions I found didn’t work, this one worked great!!
You’re most welcome, Kaplan! I’m glad this helped. 🙂
How would one restrict this to a specific taxonomy linked to that custom post type?
Off the top of my head, I’m not entirely sure. Sorry. You might want to ask this question in the WordPress.org Support Forums.
Hi Raam, first of all thank you! your code functions perfect to me! Second, I’m a new developer in wordpress and I don’t understand in which moment the parameter $pv has been completed? please Could you teach me?. Thank you.
Hi Pablo,
The
$qv
variable is passed to themyfeed_request()
function by WordPress through therequest
filter. Please see the WordPressadd_filter()
documentation for more information: http://codex.wordpress.org/Function_Reference/add_filter