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 have a featured post type and a reviews post type. I would like to include reviews of a certain category (I use categories from the posts type) as well. How could query args be crafted?

A crude example:

get_posts(array('post_type' => array('featured-posts', array('review-posts', 'featured-category'))

Need to fetch all the posts in the featured-posts type, also all the posts in the review-posts type if the assigned category is feature-category.

UPDATE: Ended up not needing to implement this but I think Stephen S had the best guess.

share|improve this question
    
Can you explain it little bit more to understand your problem. It will help you and this community also. –  yeshansachithak Apr 17 at 6:08
    
Updated for a more specific description. I try to be as general as I can but still making sense. It's tough to find search results when questions are so specific to the scope of the asker's issue. –  James Wagoner Apr 17 at 19:05
add comment

2 Answers 2

up vote 0 down vote accepted

Untested, but I think you'd need to do two separate queries and merge them together:

$args = array(
 'post_type' => 'featured-posts'
);
$featured_posts = get_posts($args);

$args = array(
 'post_type' => 'review-posts',
 'category_name' => 'featured-category'
);
$review_posts = get_posts($args);

$result = array_merge($featured_posts->posts, $review_posts->posts);

$final_query = WP_Query($result);
share|improve this answer
    
Didn't end up needing to do this query but your's makes the most sense. –  James Wagoner Apr 23 at 5:43
add comment

Have you tried doing a query on both post types and including the category? I suspect that it will look only for posts in the featured category, then limit by the two post types, but nonetheless it's worth a try.

$args = array(
    'post_type' => array( 'featured-posts', 'review-posts' ),
    'category_name' => 'featured-category'
);
$res_posts = get_posts($args);

You can always try playing with taxonomy parameters (tax_query) as well.

share|improve this answer
    
I did try that at first and your assumption was correct. I opted to not use taxonomies with the post types as I wanted to use the main post type categories. –  James Wagoner Apr 16 at 23:14
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.