I am having this problem where every time I run this, it stops on page 3. There are about 15000 products that are published. So there should be at least 30 pages.
I narrowed it down to the $loop = new WP_Query( $args ) just stopping for some reason. Not sure how to figure out what the error is.
function processPerPage($paged, $i) {
if($paged) { } else { $paged = 1; }
$args = array(
'post_type' => 'product',
'posts_per_page' => 500,
'paged' => $paged
);
$loop = new WP_Query( $args );
if($i) { } else { $i = 1; }
while ( $loop->have_posts() ) {
// do product work
$i++;
}
wp_reset_query();
}
global $wpdb;
$count = $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = 'product' and post_status = 'publish'" );
$pagestotal = $count/500+1;
$paged = 1;
while($paged <= $pagestotal) {
processPerPage($paged, $i);
$paged++;
}