Never, ever use query_posts
. It is only for the main query loop and should never be modified. There are many, many other ways of grabbing the posts you want. For example:
$args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$wcProductsArray = get_posts($args);
if (count($wcProductsArray)) {
foreach ($wcProductsArray as $productPost) {
$productSKU = get_post_meta($productPost->ID, '_sku', true);
$productTitle = get_the_title($productPost->ID);
echo '<li>' . $productSKU . '</li>';
}
}
It's worth noting that this method will only fetch simple products, and will not include product variations. If you want to grab those too, you'll need to update the $args
to 'post_type' => array('product', 'product_variation')
.