• I am trying to keep $_POST values in $_SESSION, so I can keep pagination working for a specific search. I have code below:

    if($_POST){
    	foreach($_POST as $key => $value){
    		if($value != ''){
    			$item['taxonomy'] = htmlspecialchars($key);
    			$item['terms'] = htmlspecialchars($value);
    			$item['field'] = 'slug';
    			$list[] = $item;
    		}
    	}
    	$_SESSION['realty-search'] = $list;//!empty($list) ? $list : array();
    }
    
    $search = !empty($_SESSION['realty-search']) ? $_SESSION['realty-search'] : array();
    
    $cleanArray = array_merge(array('relation' => 'AND'), $search);
    $args['post_type'] = 'listings';
    $args['showposts'] = 3;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args['paged'] = $paged;
    $args['tax_query'] = $cleanArray;

    I do a print_r on $_SESSION – and it works when form submits. But as soon as I go in another page – $_SESSION disappears? Is there a specific way I should be handling sessions in Wordrpess?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Session Values Disappears in WordPress’ is closed to new replies.