0

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.

2
  • Can you explain it little bit more to understand your problem. It will help you and this community also. Commented Apr 17, 2014 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. Commented Apr 17, 2014 at 19:05

2 Answers 2

0

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);
1
  • Didn't end up needing to do this query but your's makes the most sense. Commented Apr 23, 2014 at 5:43
0

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.

1
  • 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. Commented Apr 16, 2014 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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