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:

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 :)

  • So what exactly is your approach with the other WPSE question/answer? Please add this to your question. – kaiser Jul 31 '12 at 14:36
  • 1
    thanks, kaiser, I added the code provided in the previous StackExchange thread, for easier comparison. – versvs Jul 31 '12 at 14:55

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.
  • So, what did the corrected code look like? – Christopher Oct 24 '12 at 2:48
  • Hi Christopher, the code that solved my problem was the code provided in a previous StackExchange thread. The real issue is that i was declaring my function two times without checking if it already existed. – versvs Oct 25 '12 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.