I'm working on a wordpress plugin page that allows the user to perform a search on some custom posts. The search form is based on a script ajax and when you click on the search button, a script jquery intercepts the call and creates the ajax call for wordpress. This call launches a method within a class of wordpress plugin in question, which handles the data passed through $ _POST from the search form. Then are shown the results and clicking on one of these you will sended to the single page. The script I'm trying to do should allow the user to return from the single page to search results using the back button of browser. The problem is that this script working fine in local on my pc, but once loaded online this plugin stops working. (Sorry for the long introduction but it served to define the problem well).
The script works as follows:
- Fill the search form and click on search button
- $_POST is filled with the form data and I fill $_SESSION with $_SESSION = $_POST
- Open a result and go to the single page then hit back in the browser
Force the refresh of the page setting with controls $_POST = $_SESSION (the ride is much more complicated but this is the principle on which it is based).
ajaxResult php function This function is called on search button click
// Check if user came from single page or from search page if(!$_POST && $_SESSION['back_to_hardsoft_results']) { if( $_SESSION['back_to_page'] ) { $_POST = $_SESSION['back_to_hardsoft_results']; $_SESSION['back_to_page'] = null; } } else if( $_POST && $_SESSION['back_to_hardsoft_results']) { $_SESSION['back_to_hardsoft_results'] = null; } ...some controls with the $_POST data... $search = $this->getQueryObject($this->type, $this->taxonomies, $this->historicalFilter()); include_once TEMPLATE_PATH . CUSTOM_POST_SLUG . '-' . RESULTS_PAGE . '-page.php'; } else if ( ...$_GET...) { ...other things... }
When user visit the single page, a $_SESSION['back_to_page'] is created.
getQueryObject php function Called by ajaxResult
$args = array ( ...some args... );
$q = new WP_Query ( $args);
// Save the query for back to results from single_mediateca_page
$_SESSION['back_to_hardsoft_results'] = $_POST;
return $q; }
I've put on js file the follow string to force the refresh of page.
history.navigationMode = 'fast';
I think the problem may also relate to the browser's cache, but I don't know if is really due to it the problem. Thanks a lot for your help!