Background
I wanted my custom post types that I created in my last writeup (custom post types with archive page) to appear in my wordpress main feed. By default the custom post types do not get added to the main feed that wordpress creates. In my last write up I showed how I added the necessary rewrite rules in order to have the structure: www.domain.com/custom-p-type/feed. This will create a feed with all of those custom post types. Perfect. But what about my “main” wordpress feed?
What I wanted
What I wanted is for my www.domain.com/feed to include ALL of my sites content. Be it posts, or custom post types that I create. There are a couple of methods I found for doing this. I finally found the solution on the track in this ticket. http://core.trac.wordpress.org/ticket/12943
The solution
Here is what will add your custom post type content to your sites main feed, and leave your regular custom post type feeds specific for their respective content…
function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = get_post_types($args = array(
'public' => true,
'_builtin' => false
));
array_push($qv['post_type'],'post');
return $qv;
}
add_filter('request', 'myfeed_request');
The explanation
Thats it! Done. This code checks to see if the query var ‘feed’ exists, if it does it also checks to see if the ‘post_type’ query var IS NOT set. If the post_type query var is set, this means we are on one of our regular custom post type pages, and we don’t want to modify the way the feeds are genereated, as wordpress handles them out of the box.
So, if we are on a “feed” page, and we don’t have a post_type query var set, we must be on the home page feed (in my case). So we modify the default feed by querying for all custom post types that are not built in, and that are public using the get_post_types() function. We then append the “post” post type to the end with array_push, because I wanted my main feed to include all my custom post type content, as well as my regular post content.
Now I have the structure: mydomain.com/feed/ Which houses all of my sites published content, and each custom post type has its respective feed at mydomain.com/custom-p-type/feed/
Thingabeauty.