当我使用下一页或上一页时,我无法理解为什么我写的过滤器无效! 例如,我做出选择 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('« Next page', $the_query->max_num_pages) ?>
<?php previous_posts_link('Previous »') ?>
</div>
</div><!--end content-->`
有人可以帮我吗? 附:对不起我糟糕的英语!!
答案 0 :(得分: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有更多样本可以帮助你。