简体   繁体   中英

Wordpress pagination not working in search result page

I have a problem with pagination on search results page. First time it working after I click on submit button in search form.

The problem when I click on pagination, $_POST get null.

Thanks for help

<?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;
?>

Try this code

<?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;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM