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

tech