WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query two or more custom posts (wordpress 3.0) (3 posts)

  1. tiagommorena
    Member
    Posted 4 years ago #

    Hi,

    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!

    Regards,
    Tiago

  2. tiagommorena
    Member
    Posted 4 years ago #

    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.

  3. Austin Matzko
    Member
    Posted 4 years ago #

    query_posts(
       array(
          'post_type' => array(
             'first_custom_type',
             'second_custom_type',
          ),
          'posts_per_page' => 10,
          'post_status' => 'publish',
       )
    );
    
    while ( have_posts() ) :
       the_post();
    
    // etc.

    EDIT: Whoops, missed your reply before mine.

Topic Closed

This topic has been closed to new replies.

About this Topic