Determine if more posts are available than was asked for in `query_posts()`?

First of all: do not use query_post!

For more information read: When should you use WP_Query vs query_posts() vs get_posts()?

Use the WP_Query class to fetch your products, also pay attention that the showposts argument is deprecated, use posts_per_page instead:

$args = array(
    'post_type' => 'product',
    'taxonomy' => 'product_cat',
    'term' => $idObj->slug, // category slug
    'posts_per_page' => 25,
    'orderby' => 'title',
    'order' => 'asc',
    'paged' => $paged  // global $paged variable
);

$all_products = new WP_Query( $args );

// The Loop
while ( $all_products->have_posts() ) : $all_products->the_post();
    // do stuff here...
endwhile;

// Reset $post global
wp_reset_postdata();

To get the total number of found posts use the $found_posts property. And if you need the total amount of pages use the $max_num_pages property.

$found_posts = $all_products->found_posts;
$max_pages = $all_products->max_num_pages;

Leave a Comment