Forums › Forums › Search & Filter Pro › Pass results to another plugin or function
- This topic has 6 replies, 2 voices, and was last updated 6 years ago by Anonymous.
-
Anonymous(Private) November 18, 2018 at 11:58 pm #193889
I’m trying to integrate SFP with another plugin, specifically GeoMashup, so that a map will display the results of the current search. I can get this to work using page reloads, but when I try to update the map with AJAX, the search results always default to be every post. From the SFP docs, I’m using:
jQuery(document).on("sf:ajaxfinish", ".searchandfilter", function(){ jQuery.post(the_ajax_script.ajaxurl, { 'action': 'my_action' } , function(response_from_the_action_function){ jQuery("#mashup-map").html(response_from_the_action_function); console.log('map updated'); } }
where the PHP function my_action() calls:
echo GeoMashup::map();
I’m able to pass the current WordPress query to that PHP call using a variable, but it never seems to make a difference; the map always displays every post.
I’m not asking for help getting an entirely other plugin to work. A different way of asking the question would be: how can I capture the results of the current search query for further use in a separate AJAX call?
Trevor(Private) November 19, 2018 at 11:46 am #193897I have always used the WP Google Maps Pro plugin to do this, which has a mashup shortcode.
So, in PHP, as the while have posts loops runs, the current map ID associated with the current post is added to a string variable, and when the loop finishes that string containers a comma delimited list of Map IDs which the plugin then uses to make the map. As this is being done inside the Ajax Container, when Ajax refresh is triggered, the map refreshes.
Anonymous(Private) November 19, 2018 at 4:50 pm #194016I was on the right track then. Two questions:
If using infinite scroll, this only adds a fixed number of results at a time. Suppose you want all the results at once from a given search?
Suppose you want the map to appear above (before) the post results?
Trevor(Private) November 19, 2018 at 4:59 pm #194030Infinite scroll is an issue in these circumstances. Would you not want all results on the map?
You might want to read this thread:
https://support.searchandfilter.com/forums/topic/google-maps-integration-2/
Anonymous(Private) November 19, 2018 at 5:13 pm #194036Thank you, that thread along with your instructions helped, and the map is working.
In the case of infinite scroll, I do want all the results on the map at once, but only 20 posts displayed at once. Is that what you are saying becomes problematic? I’m willing to part with infinite scroll to get this interaction to work.
Trevor(Private) November 19, 2018 at 5:25 pm #194040The problem is the way that WordPress does its pagination and its loops. You would need to run a separate loop, outside the infinite scroll container but inside the ajax (results) container just for the map.
You would need to run a separate WP_Query, stored in a different results array variable, but apply the arguments from the original query. Are you able to output the original args?
<pre><?php print_r($args);?></pre>
to see if they still exist? Then you could edit that array to give all results (posts per page becomes -1) and use that to run a new query, maybe?
-
AuthorPosts