Adding posts of custom type into the main feed

I’m having some trouble with a subject that seems to be pretty basic, so I’m starting to feel (a little, only a little) dumb 🙂

Here’s the thing: I want my main feed to include the posts and other content (custom post types) as well.

I followed two pointers so far:

  1. First I followed this tip at WPmu.org. It works when I use only one custom type, but fails to include more than one custom type (adding them to the array).

  2. Later I followed the answer provided in this previous SE thread. This ended in an Error 500, so I went back to the first approach.

Here it is the code I’m including right now, I don’t see my error, but clearly something is not OK.

function two_customtype_in_home_loop( $query ) {
 if ( is_home() && $query->is_main_query() )
 $query->set( 'post_type', array( 'post', 'custom1', 'custom2') );
 return $query;
 }
 add_filter( 'pre_get_posts', 'two_customtype_in_home_loop' );

Edited to add: I forgot to add the code provided in a previous StackExchange thread (marked as “worked perfectly” and approved reply). The code is:

// ADDS POST TYPES TO RSS FEED
function myfeed_request($qv) {
    if (isset($qv['feed']) && !isset($qv['post_type']))
        $qv['post_type'] = array('ve_products', 'post');
    return $qv;
}
add_filter('request', 'myfeed_request');

I adapted the line:

        $qv['post_type'] = array('ve_products', 'post');

and added my two custom types:

        $qv['post_type'] = array('custom1', 'custom2', 'post');

This solution is breaking my site, and I can’t find out why.

Any ideas?

Thanks 🙂

1 Answer
1

There seemed to be two easy-to-solve problems:

  • The function was being declared twice without checking if it already existed.
  • After solving that issue, i needed to post a “post” post to refresh the feed, but after that custom post types appeared in the feed without further refreshing nor publishing standard posts.

Leave a Comment