In an attempt to speed up my query, I'm using the following arguments:
$args = array(
'post_type' => 'product',
'fields' => 'ids',
);
$query = new WP_Query($args);
While this does return an array of IDs as expected, I keep getting multiple Trying to get property of non-object in /wp-includes/query.php
notices. This happens even when I have nothing inside my while
other than the_post()
:
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
endwhile;
endif;
Is the_post()
causing this? Any idea why I'm getting these notices?
fields
entry? Never heard of that before. Does it work when you remove that?fields
=>ids
option returns an array of post ids rather than post objects, which (apparently) makes the query faster.