Reputation: 21
I'm working on a site that uses the WPeCommerce plugin. The pagination has broken, it shows the first page products on all pages. At first the loop wasn't using a custom query so I added one with a paged parameter to see if it would help. But when I print the query, paged always returns 1, even if I hardcode it to a value like 2. Does anyone know why this is happening?
<?php
$prodArgs = array(
'post_type' => 'wpsc-product',
'wpsc_product_category' => 'shoes',
'posts_per_page' => 12,
);
$prodArgs['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$prodQuery = new WP_Query($prodArgs);
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $prodQuery;
$count = 1;
?>
<div class="hidden">
<pre>
<?php print_r($prodQuery); ?>
</pre>
</div>
Upvotes: 0
Views: 4525
Reputation: 21
I found a solution.
<?php
$wp_query = array(
'post_type' => 'wpsc-product',
'wpsc_product_category' => $thd_category->slug,
'posts_per_page' => 12,
'paged' => get_query_var('page')
);
query_posts($wp_query);
$count = 1;
?>
<?php if ( $wp_query->have_posts() ) while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
Upvotes: 1
Reputation: 1162
You should add paged
parameter in wp query.
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$prodArgs = array(
'post_type' => 'wpsc-product',
'wpsc_product_category' => 'shoes',
'posts_per_page' => 12,
'paged' => $paged
);
$prodQuery = new WP_Query($prodArgs);
Upvotes: 0