I’m getting products (from a specific category) using a custom query_posts()
function. I limited the showposts
parameter to 25, so how do I know to activate pagination if there are still products (posts) to load?
My query_posts()
code looks as follows:
$args = array(
'post_type' => 'product',
'taxonomy' => 'product_cat',
'term' => $idObj->slug, // category slug
'showposts' => 25,
'orderby' => 'title',
'order' => 'asc',
'paged' => $paged // global $paged variable
);
$all_products = query_posts( $args );
And then I output my products using a foreach
statement:
foreach ($all_products as $product) {...}
I put this function in my functions.php, but $paged
nor $max_pages
don’t seem to be set. So I get false
from this function.
Now, can anyone maybe point me in some direction, as I’ve got no clue.
Use the
WP_Query
class to fetch your products, also pay attention that theshowposts
argument is deprecated, useposts_per_page
instead: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.