Rakhitha Nimesh
Rakhitha Nimesh

Reputation: 1441

Wordpress: get posts in specific categories

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

Answers (2)

Chaser324
Chaser324

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

addedlovely
addedlovely

Reputation: 3194

Use get_posts with the category and include arguments.

Upvotes: 0

Related Questions