Unexpected results when passing WP_Query from Search and Filter Pro to Geomashup, with the results updated via AJAX

enter image description here

I’m using two plugins in tandem, GeoMashup and Search and Filter Pro. Geomashup is generating a contextual map of posts from search results passed from Search and Filter Pro.

I need the results updated via AJAX, and since I always want both plugins to display the same results, I’m calling the GeoMashup map from within Search and Filter Pro’s results, which already use AJAX. I’ve written a custom results template for this, building on the default results.php provided by Search and Filter Pro.

It works except when passing a WP_Query object from GeoMashups (docs here) to Search and Filter Pro (docs here). When attempting to do this, it works on initial page load, but when updating using AJAX, it displays this where the map should appear:

… and so on, ad infinitum, evidently some kind of loop where an HTML container gets repeatedly written inside of itself. I cannot figure out where this is occurring and how to prevent it.

Inspecting the HTML, it appears that some characters are being doubled and/or then escaped with backslashes like so:

enter code hereget_field_string("_sft_category");
$categories = str_replace('Categories: ', '', $categories);
$search_terms = $sf_current_query->get_search_term();
// Make new query
$map_args = array(
's' => $search_terms,
'cat' => $categories)
$map_query = new WP_Query ($map_args);
// Show Geomashup Map
echo GeoMashup::map([
'map_content' => $map_query,
'show_future' => True,
]);

The issue persisted. To further isolate the issue, I tried it without AJAX and discovered that in certain large queries, GeoMashup was generating an error message, “Request-URI Too Long The requested URL’s length exceeds the capacity limit for this server. Additionally, a 414 Request-URI Too Long error was encountered while trying to use an ErrorDocument to handle the request.”

As long as the queries results are under a certain number (about 500 or so), it works as expected, though again not within AJAX calls. I need to keep the results in AJAX, since I’m depending on infinite scroll to allow the user to page through sometimes hundreds of results posts.

I cannot tell whether the URI length error and the infinite loop are two separate issues or two parts of the same issues, and how to troubleshoot.

Read more here:: Unexpected results when passing WP_Query from Search and Filter Pro to Geomashup, with the results updated via AJAX

Leave a Reply

Your email address will not be published. Required fields are marked *