0

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?

2

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; 

    ?> 
  • 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 :/ – Carpy Jun 2 '12 at 16:24

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.