Following Milo‘s answer, I found another workaround that works and i’m more confortable with it.
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => array(15, 17),
'posts_per_page' => 4
);
$query = new WP_Query();
$items = $query->query($args);
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- WP_Query vs get_posts
- get_posts with multiple categories
- Get posts by meta data OR title
- Can not switch the queried post in pre_get_posts hook
- Get image of latest post from taxonomies/categories
- Creating a custom search for a specific post type
- List of the years with posts presented
- Weird orderby => post__in issue
- Query posts intersecting tags and categories
- Check if loop has any categories?
- Check return value of get_posts
- How to get posts by category and by choosing a taxonomy term?
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Post incorrectly excluded when using “category__in”?
- `offset` WP_Query argument dont work via `pre_get_posts`
- Filter products on category AND tag
- How to get meta key list efficiently?
- Adding Category in WP_Query Not Working
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Ordering Posts by parent category, name ascending
- When should you use WP_Query vs query_posts() vs get_posts()?
- Retrieve posts in custom post type and specific taxonomies
- Main loop querying current template’s info only in custom category archive pages, not my posts
- A Depth Like Parameter For “get_posts”
- Advanced Search – Is this possible?
- Can’t sort custom post type by random
- Include posts from some categories while excluding from others
- pre_get_posts – Trying to get property of non-object warning
- Query posts that contain video?
- Get multiple users with meta value in one query and populate WP_User class
- WordPress query posts with multiple post_meta data
- Combine results of multiple WP_Query to resemble single WP_Query
- meta_query: check if number exists
- Filter post query to only show direct children of category
- Get a list of posts by specific category
- get_posts output always same post
- Show a 404 error page if Public query variable’s value doesn’t exist?
- WordPress Custom Search Form Displaying Unexpected Results
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- get_posts always returning the same number of posts = 5
- “paged” in WP_Query returns 0 posts
- Specify strict ‘order by’ in WordPress query
- Why posts array is empty?
- How to check the array values, what WP_Query has brought to me?
- get_posts() and global variables
- complex get_posts() query to select child pages
- How to set up hierarchical relationships without using plugins / meta query
- How to add custom meta to ‘pre_get_terms’?
- Set front_page programatically after user login via query, while leaving site option alone
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Shortcode for custom query not returning results when attributes are added
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- Check if searched number is within the post meta value
- WP_Query Taxonomy categories filtering
- Yoast primary category query modification
- Hide products in uncategorized category from search results
- Query where ANDing slug values not working
- How to load a script code only in posts?
- How to give classname to post if post has no content?
- How to filter query loop block with a search string from the query parameters
- Update query for wp_posts and wp_postmeta
- get_posts custom field
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- How to hide posts of a specific custom category in WordPress?
- How to apply a function to a metadata value before launch a WP Query?
- Posts query according to meta box date
- How to echo woocommerce category name
- Get specific ACF key and value from all posts – no access to DB
- mysql query order by
- Woocommerce: order posts by meta key
- WP_User_Query and user posts
- Related Posts function not working
- How to display a list of posts in same child category as current post
- Notice thrown when creating numeric pagination on custom query
- Slider won’t work with custom query
- wordpress udpate query not equal to
- WP_Query with one category in args shows other categories
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- How to exclude a category name from showing?
- Loop categories by recent post
- How order posts from category by date and comment count?
- Get the child category ID of current category
- Write WP Query that selects posts that are part of the same two categories
- Related Posts Excluding Certain Categories
- Getting the permalink to the latest post from a category
- Create query for both custom post type and category
- What is wrong with my WP_Query Arguments?
- WP_User_Query orderby meta_val_num
- WP_Query custom order and pagination
- How to access $wp_query object from array of posts given by get_posts?
- Function using get_posts() with tax_query not working when called from functions.php
- get_posts query matches too many results
- How to SQL query posts IDs by categories AND authors?
- How to properly use Categories with Custom Post Types
- Unable to paginate a custom page query
- Using in ‘category_name’ in ‘$query->set();’?
- Include one page/post into query which is already returning posts
- I am officially missing something about transient posts