I'm attempting to query Products in WooCommerce and return their IDs as an array that can be used to filter conditionally. I'm using ACF Pro to add custom fields into the product, for which I'm then using conditional code.
I spoke to my developer friend, who suggested this approach which should store the array in the $ex_id or $inc_id variable;
<?php
query_posts( $args ); while ( have_posts() ) : the_post(); ?>
<?php if( in_array( 'yes', get_field('exclude') ) ) { ?>
<?php $ex_id[] = the_id() ;?>
<?php } else if( in_array( 'yes', get_field('include') ) ) { ?>
<?php $inc_id[] = the_id() ;?>
<?php } ;?>
<?php endwhile; wp_reset_query(); ?>
This wasn't working, so I simplified the conditional code to find that the return id was that of the front page;
<?php
query_posts(); while ( have_posts() ) : the_post(); ?>
<?php the_id() ;?>
<?php endwhile; wp_reset_query(); ?>
If I add $args (specially; 'post_type' => 'product', 'showposts' => -1) the query works and the correct IDs are returned, only they are printed on the screen.
Does anyone know how I can query and store as a variable?