Get posts from multiple categories with category

I want to get posts that have one (not all) of a particular set of categories that have a specified category.

For example, I want all posts with the categories Apples, Bananas, Oranges that have the category of GreenBeans.

Read More

How can I do this in WordPress?

Related posts

Leave a Reply

3 comments

  1. I think I figured it out.

    $args= array(
        'post_type' => 'post',
        'posts_per_page' => '1',
        'orderby' => 'rand',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'relation' => 'OR',
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-1',
                ),
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-2',
                ),
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-3',
                ),
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-4',
                ),
            ),
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => 'category-5',
            ),
        )
    );