Wordpress分页在搜索结果页面中不起作用

时间:2014-03-08 04:50:21

标签: wordpress

我在搜索结果页面上遇到分页问题。我点击搜索表单中的提交按钮后第一次工作。

当我点击分页时出现问题,$ _POST变为空。

感谢您的帮助

<?php
foreach($_POST as $key => $value){
   if($value != ''){
     $item['taxonomy'] = htmlspecialchars($key);
     $item['terms'] = htmlspecialchars($value);
     $item['field'] = 'term_id';
     $list[] = $item;
   }        
}  
$cleanArray = array_merge(array('relation' => 'AND'), $list);
$args['post_type'] = 'listings';
$args['showposts'] = 12;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;  
$args['tax_query'] = $cleanArray; 
$the_query = new WP_Query( $args ); //data is sanitized inside wp_query class  

while ( $the_query->have_posts() ) : $the_query->the_post();

the_title();
endwhile;
?>

1 个答案:

答案 0 :(得分:3)

试试此代码

<?php
$list = array();
$item = array();
if(!empty($_POST)) {
       $_SESSION['your-var'] = $_POST;
}

  foreach($_SESSION['your-var'] as $key => $value){
   if($value != ''){
     $item['taxonomy'] = htmlspecialchars($key);
     $item['terms'] = htmlspecialchars($value);
     $item['field'] = 'term_id';
     $list[] = $item;
   }        
}  
$cleanArray = array_merge(array('relation' => 'AND'), $list);
$args['post_type'] = 'listings';
$args['showposts'] = 12;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;  
$args['tax_query'] = $cleanArray; 
$the_query = new WP_Query( $args ); //data is sanitized inside wp_query class  

while ( $the_query->have_posts() ) : $the_query->the_post();

the_title();
endwhile;
?>
相关问题