Support » Themes and Templates » Query two or more custom posts (wordpress 3.0)

  • Resolved tiagommorena



    Really excited about WordPress 3. No more workaround to deliver a simple interface for my clients! But, since my PHP skills are very limited (minimal, really) I was wondering how can I query two or more custom posts types in the same query – like a most recently added posts feature in the footer. I used to do this with categories like this:

    <?php query_posts('cat=3,4&showposts=10&order=DSC'); ?>

    I research a lot in the web and found this code for the loop:

    <?php global $wp_query;
    		$wp_query = new WP_Query(array( 'post_type' => 'destaques', 'posts_per_page' => 10, 'post_status' => 'publish'));
    		while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

    I works fine with one post_type, but when I put a second post_type it won´t work.

    Please, if anyone can, help me!


Viewing 2 replies - 1 through 2 (of 2 total)
  • It´s easy, just find a answer looking into the codex:

    <?php query_posts( array( 'post_type' => array('type1', 'type2') , 'posts_per_page' => 10 ) ); ?>

    Hope this helps someone.

          'post_type' => array(
          'posts_per_page' => 10,
          'post_status' => 'publish',
    while ( have_posts() ) :
    // etc.

    EDIT: Whoops, missed your reply before mine.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query two or more custom posts (wordpress 3.0)’ is closed to new replies.