PHP memory friendly alternative to get_posts()

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',
    )
);

Leave a Comment