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.

I'd like to create a custom loop that includes all Post types: Post and Video. Then I'd like to specify to show all posts of the post type Video, but only show posts that are in the category "Videos."

Here's what I'm thinking:

<?php
    $args=array(
        'post_type'=> array('video', 'post')
                 if( get_post_type() == 'post' ) {
                'category_name' => 'videos'
                 }      
    );
    $video_post_query = new WP_Query($args);    
?>

I know it sounds strange but this is a work around because the custom post types are new and it's going to take time before I'm able to take all the old video posts and put them into the custom post type. Even if I didn't have this issue I still think it would be useful to know how to define a multiple post type loop that specifies different parameters for each post type.

share|improve this question
3  
How about a different question? How about: "How can I change all posts in the video category to the video post type?" Will that work for you? It will be easier to accomplish than what you are asking, and it sounds like what you really want anyway, right? –  MikeSchinkel Dec 18 '10 at 9:32
    
The only reason I didn't ask this is that there's actually several different post types and some of the are so structurally different they have to be migrated by hand. For example my old slideshows took advantage of the native attacments and used the description field of each img. Now its a paginated post type with img and video slides that use custom fields for everything. The video post type probaby can be done automatically but ill need to do this custom loop elsewhere anyway. –  matt Dec 18 '10 at 15:34
    
Please check your code, I think $args is in the wrong line. –  hakre Dec 18 '10 at 16:59
    
@hakre: I edited the post. Is that what you mean? –  matt Dec 18 '10 at 17:37
    
your code gives php syntax errors, but at least $args must be defined before used and well, that's at least more in the edited variant as it was in the previous :) –  hakre Dec 20 '10 at 14:05

1 Answer 1

Can I create a loop with multiple post types and specify different $args for each post type?

Simply put no... you can't have a single query instance with three differing sets of arguments. The reason why is pretty simple, the query class will only take one array of arguments per instance.

If you want differing sets of results, then you need additional queries. And sometimes, just sometimes, plonking everything into one query isn't necessarily the most efficient means for grabbing the data.

I don't work on high traffic websites to have any real idea about what queries work out best performance wise, i simply wished to point out, having one query doesn't necessarily translate into being more efficient.

share|improve this answer

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.