As documented in the codex you could use the following
$query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) );
//post has to be in category with ID 2 AND 6
Related Posts:
- WP_query category__in not working, only pulls from first category
- How to get posts by category and by choosing a taxonomy term?
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- How to use the_posts_navigation for wp_query and get_posts?
- WP_Query vs get_posts
- Exclude or Include category ids in WP_Query
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- Get posts from Network (Multisite)
- How to order by post_status?
- Using get_posts vs. WP_Query
- Delete all posts from WordPress except latest X posts
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Sanitation needed for WP_Query or get_posts calls?
- Differences Between WP_Query() and get_posts() for Querying Posts?
- WP_Query to show post from a category OR custom field
- Get Recent Posts by Date in Multisite
- get_template_part in for loop
- Use of caller_ get_ posts
- How-to exclude terms from the main query the most performant way?
- ajax category filter
- Is it possible to select against a post’s parent’s fields with WP_Query?
- Query all posts where meta value is empty
- Display recent posts from the same category as current post in sidebar
- Get posts by meta data OR title
- How to filter by category in REST API, excluding posts also in other category term?
- Get_post() with meta_key when compare is a date
- get_posts not finding argument: post_name
- Meta Query with date and time on the same Day before given time
- Counting number of posts with Category B in Category A
- Get posts with condition on comment meta value
- How to order category.php loop by ‘meta_value’?
- Function to check if author has posted within the last x days
- Use Transient API to cache queries for all posts in all categories?
- How can I display recent posts from a particular category in my header?
- Sorting Posts by custom field
- Use post__in and post__not_in together?
- What should I use, get_posts or wp_query for less CPU load?
- Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?
- How to get post from all Blog Multisite to the Main Site?
- WP Query post meta value
- Get all posts without tags
- get_posts() seemingly ignoring post_type
- Can not switch the queried post in pre_get_posts hook
- How to find out what “Blog pages show at most” is set to [duplicate]
- Count posts returned by get_posts in external PHP script
- WP Query with multiple categories – passing an array works?
- wp_query display posts from same category of the post
- Trying to check and see if a post has a featured image outside of the main loop
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- WP_Query order by date in meta_value
- How get posts from a subcategory of a category by name?
- get complex results set according to category structure
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Searching through different categories on different pages code is not working
- Get image of latest post from taxonomies/categories
- How To Remove/hide some specific categories from two different categories widget from sidebar
- Adding multiple post queries with parent and children to page – Best Way
- How to select posts from one category but exclude posts in another category?
- How do you Query posts with nothing in common?
- WP_Query, tax_query and term_meta: How to?
- Get posts for last working week in WP_Query
- Get Category Archive Template Name Dynamically
- WP_Query arguments to fetch custom post type posts which are in certain category?
- How do I reset this wp_list_categories query?
- How can you get first post, last post and post count in a category?
- get_posts – get all posts by array of author
- How to get count of posts assigned to given category?
- Create a sitemap without a plugin – get parent pages only?
- Creating a custom search for a specific post type
- How to show subcategories using loop?
- get_posts – find out if querystring was crap and fallback is used
- Get posts for which a custom field is not present, with get_posts
- Creating query to show which editor (classic or block) was last used to edit a post/page
- get_posts() not working with multiple statuses
- List of the years with posts presented
- Remove a specific category ID from related post
- Complex Category selection as per user input
- Show all post for a given category
- Five posts from a category in footer
- Return only post(s) which have post_excerpt
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- How to get all unique categories for posts in loop?
- Help with WP_Query – Too many mySQL queries
- WP_Query() and get_posts() can’t handle over a thousand posts?
- Display Featured Post by Categories and Avoid duplicated posts
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- category query for pages not working
- add active class based on permalink and url
- Weird orderby => post__in issue
- Can we return all category (not post) with Custom Query Filter? [closed]
- Query posts intersecting tags and categories
- Query posts from category A, and from either category B or C
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Combining categories (Query posts with multiple taxonomy terms)
- Check if loop has any categories?
- Filtering out child category posts from parent category archive not working
- Exclude Category filter from Portfolio section