WP WPQuery, not running properly in WP CLI

I’m running a simple query just to find simple WooCommerce products, here is the query which works fine in the header of the site:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'product_type',
            'field' => 'slug',
            'terms' => array('simple')
        ),
    ),
);

$simpleProducts = new WP_Query($args);

This query returns 1065 products which are correct. If I run the same query through a WP CLI command, I get 0 posts… however, if I remove the tax query it’s returns all the products on the site.

Here is the command that runs:

// Add the command.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
   \WP_CLI::add_command('update-stock', \stockChecker::syncStockFile());
}

Has anyone had this issue with WP CLI?

EDIT

To add, this runs fine:

$args = array(
    'post_type' => 'product_variation',
    'posts_per_page' => -1,
);

$products = new WP_Query($args);

0

Leave a Comment