Use the fields
argument to grab just the ID – will save you a ton of memory đ
$product_ids = get_posts(
array(
'posts_per_page' => -1,
'post_type' => array( 'product', 'product_variation' ),
'fields' => 'ids',
)
);
Related Posts:
- Make WP_Query more efficient?
- Out Of memory issue on post per page parameter
- How to use WP_Query() on single.php?
- Exec wp query in slow motion to avoid memory error?
- WP_Query (or WC_Product_Query) out of memory
- Meta_query compare operator explanation
- Reduce or prevent calling of update_meta_cache
- Order wp_query by calculated field
- new WP_Query() – what is the earliest valid hook?
- Extending WP_Query â Optimise SQL query
- WP_query and pagination?
- How to get post from all Blog Multisite to the Main Site?
- Select posts with any post_type from database?
- Sort in WP_Query(), not filter? Is it possible?
- Better to make new wp_query or only modify main query each time?
- Using WP Query to search within ALL keys in meta query
- How to display images in related posts?
- Search product by brand name in wp_query
- What is the difference in a query when using a fieldname as a meta key vs orderby field?
- Get all post IDs from current WP_Query – not just currently visible
- How to Modify Taxonomy Archive Page with Search Parameter?
- WP User Query multiple AND OR query problem
- $wpdb->insert inserting two rows in database
- More than 1 Year Date Query
- Is it possible to dynamically get queried term AND taxonomy?
- posts_per_page not working
- WP Query for variable taxonomies
- WP_query Date Range results not matching loop
- Pull post meta with post_query?
- How to use WP_Query to display many posts?
- $wpdb select date range of posts
- Meta Query relation âANDâ not working
- Complex WP_Query (two post types and multiple operators)
- Five posts from a category in footer
- Return only post(s) which have post_excerpt
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Front page with registered query params in URL shows blog archive instead of front page
- Order by empty custom field
- Cutom wp_query for geolocation search, pagination not working
- Warning: Invalid argument supplied for foreach(). when creating a WP_query
- Help ordering Post loop by two meta values
- Display most popular in the past two days
- WP_Query (list) posts according to author’s custom field
- New WP_Query loop in admin causes problems
- How to sort a custom wordpress query by combination of meta values?
- Get author if post has multiple authors
- Hide posts with meta key in WP_Query
- What happens to the default query when I use WP_Query?
- Modifing archive query affects show post count function
- For what queries is conditional tags informative?
- JSON – Create rest api endpoint for Advanced Custom Fields
- Query_vars support in Rest API
- Is it possible (and how to) query single Gutenberg blocks?
- Continue or break the while loop
- Get meta_value of a specific meta_key from all posts belonging to a specific custom type
- Custom query filter by ACF date custom field
- Nested array issue in meta_query
- Query by key or author
- Sorting posts by Multiple custom fields in defined order
- Why doesn’t my WP Meta Query return any results?
- How to build the WP_Query using the code?
- How go give $value to wp_query
- Show multiple tax_query from 2 or more post_type in a single code
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- How to make the ‘request’ filter work?
- How to use rewind_comments() – when and how to use it?
- How to make a query returning pages from multiple parents
- create a custom query for posts managed by Restrict Content Pro
- How do I stop the same post showing multiple times in a archive?
- Related categories order posts by category
- Finding post ID dynamically on click
- paginate_links method doesn’t show second page of my custom wp_query
- Wp_Query Post per page not working?
- Order Element By Custom Field in WordPress
- Display All Top Child Categories / Taxonomy
- how to get custom attachment url?
- ACF Post Object meta-query by title not ID
- Case insensitive ORDERBY in wpquery
- Sorting with meta_query and multiple, optional meta keys
- getting posts by tags
- WP_Query & Duplicate entries
- Query child posts with tax query on parents
- How to break up output of posts for different terms on same page?
- Get posts by similar names and categories
- Calculating efficiently on large amount of data generated by wp_query
- WP Query issue for multiple values
- Include post_status check within $wpdb query
- Return on a quest all these meta_value
- Complicated WP_Query
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Divide WP_Query posts by date & post type
- Custom query to show posts
- New WordPress WP Query using posts from certain categories
- Taxonomy related query not working
- Multiple Orderby is not working right
- WP query based on two meta queries
- WordPress website links redirect to homepage
- Use value from meta key array for use in WP_Query
- WP_Query sort by ACF date field (newest first) with blank dates first
- Pagination only showed when no category is set in wp_query