Reputation: 1441
I want list posts from given categories which belong to certain post ids.
Example: Posts from categoryA or categoryB which has the id 1,2,3,4,5
Upvotes: 2
Views: 6947
Reputation: 488
Using get_posts
with the post__in
and cat
will likely meet your needs.:
// Create your query argument array
$args = array(
'cat' => '1,2', // Where 1 and 2 are the category ids of Category A and Category B that you want posts containing either of.
'post__in' => array (1,2,3,4,5) // Where 1-5 are post ids
);
// Retrieve posts
$post_list = get_posts( $args );
$post_list
will be an array of posts retrieved based on the query parameters passed to get_posts
.
You can get more info on get_posts
here and more info on valid query parameters here.
Upvotes: 2