Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: get posts in specific categories

Tags:

wordpress

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

like image 280
Rakhitha Nimesh Avatar asked Feb 10 '26 16:02

Rakhitha Nimesh


1 Answers

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.

like image 55
Chaser324 Avatar answered Feb 12 '26 15:02

Chaser324