I have written a custom wordpress search. The problem is that the pagination is not working.
The pagination (1, 2 , 3 , 4 ,5 >>) appears on the web site, but when i press page 2 (or anything else) no new query data is presented. Its only showing my first page (first 9 products.
Can someone please help me find out what i am doing wrong? :)
please see the web page : http://tevodekk.kamy.no/felgalle/
$display_count = 2;
global $wp_query, $paged;
$pages = $wp_query->max_num_pages;
//LAGER SØKOUTPUT
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo "paged " . $paged;
$showposts = 10;
$args = array(
'posts_per_page' => 20,
'post_type' => 'any',
'post__in' => $WPIDs,
'orderby' => 'meta_value',
'meta_key' => 'cf_dimensjon',
'order' => 'ASC',
'number' => $display_count,
'paged' => $paged
);
$wp_query = new WP_Query( $args );
//The Loop
while ( $wp_query ->have_posts() ) : $wp_query ->the_post();
global $product;
//echo $query->request;
if((int)$product->stock > 0 ){
$url2 = get_permalink( $product_id );
$url = $product->add_to_cart_url($p);
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$stock = get_post_meta( get_the_ID(), '_stock', true);
$pic = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
$bredde = array_shift(woocommerce_get_product_terms($product->id, 'cf_felgbredde', 'names'));
$bredde = get_post_meta( get_the_ID(), 'cf_felgbredde', true );
$hoyde = array_shift(woocommerce_get_product_terms($product->id, 'cf_hoyde', 'names'));
$hoyde = get_post_meta( get_the_ID(), 'cf_hoyde', true );
$dim = array_shift(woocommerce_get_product_terms($product->id, 'cf_dimensjon', 'names'));
$dim = get_post_meta( get_the_ID(), 'cf_dimensjon', true );
$innpress = array_shift(woocommerce_get_product_terms($product->id, 'pa_felg- bredde', 'names'));
$innpress = get_post_meta( get_the_ID(), 'cf_innpress', true );
$produktgruppeny = array_shift(woocommerce_get_product_terms($product->id, 'pa_produktgruppeny', 'names'));
echo '<div>
<div style="float:left;"><a href="'.$url2.'"><img width="64" height="64" src="'.$pic.'" class="attachment-shop_catalog wp-post-image" alt="Standard bilde - sommerdekk" style="padding-right: 10px;"></a></div>
<div style="float:left;width: 390px;padding-top: 12px"><h3><a href="'.$url2.'">'. the_title( $before, $after, $echo ) .'</a><span class="amount" style="font-weight: normal;color: #f7f2f7;" >' . ' ' . ' '. '</span></h3>
<span style="color:#FFFFFF;"> Dim: '.$dim.' Innpress: '.$innpress . ' Lager : ' . $stock . ' </span></div>
<div style="float:left;margin-left: 45px;padding-top: 12px;"><form class="cart" method="post" enctype="multipart/form-data">
<div class="quantity buttons_added" style="float: left; margin-right: 11px;"> <input type="button" value="-" class="minus">
<input type="number" step="1" min="1" name="quantity" value="1" title="Antall" class="input-text qty text" size="4">
<input type="button" value="+" class="plus"></div>
<input type="hidden" name="add-to-cart" value="'.get_the_ID().'">
<button type="submit" class="single_add_to_cart_button button alt">Kjøp</button> ' . $price . ' kr ' . '
</form></div>
<div style="clear:both;border-bottom: 1px solid #827f82;margin-bottom: 0px;padding-top: 0px;"></div>
</div>'; }
//
endwhile;
wp_pagenavi();
- Removed offset and it works great!
$offset
using$page
which doesn't look to be set in the code above. You probably mean to use$paged - 1
.offset
withpaged
, the presence ofoffset
causes WP to ignorepaged
, use one or the other.