I solved this using the HistoryAPI.
Since my ajax returns objects that has response
, html
and query
, I pushed the html results of the search to the history state with
window.history.pushState( date_out.html, null, null);
where data_out
is the object returned from the ajax call.
Then I added a button on the single advert page that will do
window.history.back();
on click. This will send me to the search results page. Then I can check the url of the search page (this can be hardcoded or pulled from the localization object where it’s set with WordPress), and if there is anything in the history.state
which corresponds to the search html I just place it after the desired div.
Then inside that check I also push the empty state in the history just to be sure that when you go to some other page and push back that you won’t see any search results.
Seems to be working fine 🙂
Related Posts:
- Run again current query via ajax but changing a var
- i’m trying to get all my media query attachments via ajax in wordpress
- Wp admin ajax load more
- Syntax error on query_vars while handling with Jquery
- Same query in category.php and in function.php, but different result
- How to fetch meta_value and meta_key in matrix after ajax request by post_id
- Ajax Form data is not posted back to the get_results()
- Loads posts of different year via AJAX call
- AJAX loading with custom parameters
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- How to check if I am in admin-ajax.php?
- Ajax in a settings page (update_option is undefined)
- admin-ajax.php vs Custom Page Template for Ajax Requests
- Saving (Updating) Post / Page Edits With AJAX
- Is there a hook that fires before an ajax call?
- AJAX request from Chrome Extension to WordPress Website
- How to correctly load wordpress in a non WP script for AJAX request
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Why is admin ajax reloading my page
- Plupload in metabox – AJAX action not working in Class
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- CPU usage: AJAX and Heartbeat API on admin pages
- Ajax call in wordpress not working for subscriber user in front site
- Solve cors problem using rest api or ajax
- Can part of my WordPress website be headless?
- Nonces, AJAX, script variables & security in WordPress
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- Why does WordPress Heartbeat login not refresh the nonces?
- Why would admin-ajax.php redirect to the home page for logged out users?
- Admin Ajax and HTML5 Formdata
- Implementing an AJAX POST API call in wordpress
- Placement of add_action() for ajax callback?
- WordPress ajax problem need wordpress expert?
- Identical wp_rest nonce returned from rest_api
- Ajax WordPress Login needs to be stayed in current page Url without redirecting
- wp_ajax function did not call
- Ajax image upload with media_handle_upload and form.js
- Can’t get result from sql using ajax result
- Get the_content with ajax
- Caching-Plugins and Ajax-Page-Parts
- Load more posts with multiple queries
- Ajax loading duplicate post
- WordPress AJAX – how to return true or false in the callback function
- Admin ajax error 400 when passing select value to populate another select
- WordPress Ajax POST Error 403 admin-ajax.php
- How do I detect in which page ajax_query_attachments_args is loaded?
- Ajax post returning full html page as response
- Which allowed API hooks work to add wp_ajax action?
- Pass additional parameter with async upload
- Ajax store response json in variables
- Performance optimization of tree like structure
- WordPress search results with Ajax, get_post_type() not working
- How can I set cookies on both secure and non-secure origins at the same time?
- Variable Products Being Added to Cart with AJAX on Shop and Category Pages
- Is it secure to use admin-ajax.php in front?
- Best way to use ajax front-end?
- merge wp rest api query to get posts per category does not work
- use jQuery.load() to include a php file in a div, wp_query() is part of php file
- How to make a fetch() POST request to wordpress rest api?
- Load more posts in the same category – Ajax + Timber
- Load more posts (Ajax) in tabbed sidebar on single.php
- Something strange with ajax
- admin-ajax.php returns 0 even when the post status code is 200 OK
- is there’s a way to get the next page content generated by page break block with ajax call?
- Merge PDF files from post custom fields(ACF) into one PDF file and respond back the created PDF file, WordPress(AJAX Request)
- REST public POST giving 403 forbidden nginx
- Passing value from select form with Ajax not working
- Sending email through Ajax without page refresh hangs on admin_ajax.php
- Is there a public ajax endpoint?
- Why Ajax Doesn’t Work?
- How can i do public ajax call?
- How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)
- Content including hooks inside wp-settings.php are being called twice in WordPress
- Frontend AJAX Media Upload returning 404
- Can’t GET Variable from AJAX URL
- JS global variable doesn’t update
- 404 error custom post type rest api
- How to update cart total after AJAX success
- How to implement AJAX within a class storing shortcode atts as class variables
- Jquery wrap permalink in a data-attribute?
- (Frontend AJAX) get post data WITH image thumbnail?
- Load .php file into div using ajax
- AJAX Post from same domain to a wordpress page
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Using AJAX for dynamic settings pages
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- AJAX admin Internal 500 error Failed to Upload
- Class property not visible inside ajax callback function?
- How to get data with Select AJAX PHP
- Add “load more” functionality to an AJAX response
- weird Internal Server Error – no error log produced
- Why are the most recent posts not appearing in a fetch request, unless I’m logged in?
- Successful ajax call returns lots of whitespace and text of code with 0
- How to submit a button automatically after every scheduled hours?
- At what stage does wp_ajax hooks gets applied during WordPress request?