0

我不明白为什么我写的过滤器在我使用下一页或上一页时不起作用!例如,当我尝试查看帖子的其余部分时,我选择 minprice= 200 点击搜索,过滤器仅找到价格 > 200 的帖子,页面显示相同的页面。这是代码!!

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-->`

有人可以帮助我吗?PS对不起我糟糕的英语!

4

1 回答 1

0

我相信您需要在paged查询中添加一个参数。

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

这篇 Codex 文章有更多示例可以帮助您进行操作。

于 2013-04-09T00:52:30.960 回答