I’m sure there’s some very easy explaination for this, but I’m stuck. I am just trying to put a nice, simple recent posts element on the front-page of a site and for some reason when I try to use:

$args = array( 
    'post_type' => array('post','recipes'), 
    'posts_per_page' => 4
);
query_posts( $args );
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    ...

endwhile; 
wp_reset_postdata(); 

it won’t show the recipes. The strange thing is that if I call ‘post’ and ‘page’ it’ll display both, but as soon as I add ‘recipes’ it just displays the first type requested that’s not recipes. Am I missing something easy here?

Edit:

Updated with WP_Query instance instead of query_posts, still doesn’t work.

$argz= array(
'post_type' => array('post','recipes'), 
'posts_per_page' => 4
);

$my_query = new WP_Query($argz);

Still doesn’t work. Still returns the correct query var and everything, but doesn’t display both post types.

4 Answers
4

I had this problem with querying on two custom post types, using WP_Query. I had no problem querying for one type or the other in the array, but not both at the same time.

Did not work:

$args = array( 
    'post_type' => array('custom_type_1','custom_type_2'), 
    'posts_per_page' => 4
);

Did work:

$args = array( 
    'post_type' => array('custom_type_1'), 
    'posts_per_page' => 4
);

Did work:

$args = array( 
    'post_type' => array('custom_type_2'), 
    'posts_per_page' => 4
);

Awfully confusing to say the least.

Solved the problem by making sure that both custom post types had the “Make ‘Custom Post Type Name’ translatable” checkbox for WPML. WPML must not like it if you try to query on two post types where one is translatable and the other is not.

(I’m on WordPress 3.4.1 and WPML 2.5.2 – latest as of the date of this post)

Leave a Reply

Your email address will not be published. Required fields are marked *