I am using folowing code to store posts ids into array:
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'desc');
$id = array();
$counter = 1;
$products = new WP_Query( $args );
if ( $products->have_posts() ) : while ( $products->have_posts() ) : $products->the_post();
$id[$counter] = get_the_id();
//custom_shop_array_create($product, $counter);
$counter++;
endwhile;
endif;
?>
However it doesnt work because if I put print_r($id)
after endif it only prints id of last post. Where am I making mistake?
Thanks in forward