Form Post / Session Variables not Working in Query with Pagination
I am developing a custom search where the user inputs data on the first page with a form. Upon clicking submit, the user is brought to a second page for the results. I pass the data via pulling in the form results via $_POST. Then assigning it to a $_SESSION.
It works great… until I hit the next button to go to page 2. The pagination works fine, but the issue is that the variables do not load on the 2nd, 3rd, etc pages.
The caveat is that if I am logged in… it works perfectly! But once I test in an incognito window… it does not work.
Header file: At the top I call the session:
?php session_start(); ?
Page 1 is a form:
form id=theform method=POST action=/search-results
input type=text name=tax_1 id=tax_1 required
input type=text name=tax_2 id=tax_2 required
/form
Page 2: Search results This has pagination.
// I use the 2nd condition because $_POST does not work after I go to the next page.
if( get_query_var('paged') == 0 $_POST['tax_1'] != '' ){
$flagx = 1;
$_SESSION['tax_1'] = $_POST['tax_1'];
$tax_1 = $_SESSION['tax_1'];
$_SESSION['tax_2'] = $_POST['tax_2'];
$tax_2 = $_SESSION['tax_2'];
} else {
$tax_1 = $_SESSION['tax_1'] ? $_SESSION['tax_1'] : '';
$tax_2 = $_SESSION['tax_2'] ? $_SESSION['tax_2'] : '';
}
I would greatly appreciate any help!!!