php - Paged WP_Query is quitting on page 3

admin2025-04-21  1

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++;

}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745241569a292039.html

最新回复(0)