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

Related posts

Leave a Reply

2 comments

  1. 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.