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.
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.