Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So i know how to combine post types into 1 loop and out put the loop. Below is what i have:

        <?php

        $args = array(
            'post_type' => array('post','movie','actor'),
            'posts_per_page' => '20',
        );

        query_posts( $args );
        while ( have_posts() ) : the_post(); 

            the_title();

        endwhile; 

        ?> 

This works as expected, however is it possible to specify different arguments for each post type, while keeping them within the same original loop.

So for example i need to add a meta_key=value argument to the movie & actor post types. Is this possible?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Could you do something like this?

<?php

    $args = array(
        'post_type' => array('post','movie','actor'),
        'posts_per_page' => '20',
    );

    query_posts( $args );
    while ( have_posts() ) : the_post(); 

        global $post;

        if (($post_type == 'movie') && (get_post_meta($post->ID, 'meta_key', true) == 'your-value')) {

             // Display your content for Movie Post Type with meta value set

         } else if (($post_type == 'actor') && (get_post_meta($post->ID, 'meta_key', true) == 'your-other-value')) {     

             // Display your content for Actor Post Type and Other Meta Value

         }    

    endwhile; 

    ?> 
share|improve this answer
    
Thx for the answer. Yes currently this is the only way i've figured out around the problem. However, this messes up the posts_per_page argument in the original query due to not every post having the specific meta values. But this may have to do :/ –  Blackbird Jun 2 '12 at 16:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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