2013-04-09 144 views
0

我不明白为什么我写的过滤器在使用下一页或上一页时不工作! 例如我做我的选择 minprice = 200 点击搜索和过滤器只查找价格> 200 当我试图看到其他帖子的页面显示我同一页。 这是代码!用tax_query和meta_query列出搜索结果

foreach($_POST as $key => $value){ 
    if($value != ''){ 
     $item['taxonomy'] = htmlspecialchars($key); 
     $item['terms'] = htmlspecialchars($value); 
     $item['field'] = 'slug'; 
     $list[] = $item; 
     if ($key == "minprice") { 
       $minprice = $key; 
       if($value > 0) { 
        $valminprice = $value; 
       } 
     } 
     if ($key == "maxprice") { 
       $maxprice = $key; 
       if($value > 0) { 
        $valmaxprice = $value; 
       } 
     } 
     if ($key == "minmq") { 
       $minmq = $key; 
       if($value > 0) { 
        $valminmq = $value; 
       } 
      } 
     if ($key == "maxmq") { 
       $maxmq = $key; 
       if($value > 0) { 
        $valmaxmq = $value; 
       } 
      } 
     if($key == "location"){ 
       $lockey = $key; 
       $valloc = $value; 
      } 
     if ($key == "type") { 
      $typekey = $key; 
      $valtype = $value; 
     } 
     if ($key == "property") { 
      $propkey = $key; 
      $valprop = $value; 
     } 
     if ($key == "range") { 
      $rangekey = $key; 
      $valrange = $value; 
     } 

    }  
} 

$args = array (
      'post_type' => 'listings', 
      'posts_per_page' => 2, 
      'meta_query' => array(
           array(
           'key' => 'wtf_price', 
           'value' => array($valminprice, $valmaxprice), 
           'type' => 'NUMERIC', 
           'compare' => 'BETWEEN' 
           ), 
           array(
           'key' => 'wtf_mq', 
           'value' => array($valminmq,$valmaxmq), 
           'type' => 'numeric', 
           'compare' => 'BETWEEN' 
           ) 
          ), 

      'tax_query' => array(
           array(
            'taxonomy' => 'location', 
            'field' => 'slug', 
            'terms' => $valloc,  
           ), 
           array(
            'taxonomy' => 'type', 
            'field' => 'slug', 
            'terms' => $valtype,  
           ), 
           array(
            'taxonomy' => 'property', 
            'field' => 'slug', 
            'terms' => $valprop, 
           ), 
           array(
            'taxonomy' => 'range', 
            'field' => 'slug', 
            'terms' => $valrange, 
           ) 
          ) 
      ); 

    $the_query = new WP_Query($args); 



<?php while ($the_query->have_posts()) : $the_query->the_post();?> 
    <div class="post propbox <?php if (++$counter % 2 == 0) { echo "lastbox";}?> clearfix" id="post-<?php the_ID(); ?>"> 
<div class="archimg"> 

THE CONTENT.... 

</div> 

    <?php endwhile; wp_reset_postdata(); ?>  

<div class="row page-navigation"> 
    <?php next_posts_link('&laquo; Next page', $the_query->max_num_pages) ?> 
    <?php previous_posts_link('Previous &raquo;') ?> 
</div> 



</div><!--end content-->` 

有人可以帮我吗? P.S.对不起我可怕的英语!

回答

0

我相信你需要为你的查询添加一个paged参数。

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array (
      'post_type' => 'listings', 
      'posts_per_page' => 2, 
      'paged' => $paged, 
      // etc. 
      ); 

This Codex article有更多的样本,应该让你去。