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:
<iframe name="\"gm-map-1\"" src="\"https:\/\/website.com\/?geo_mashup_content=render-map&map_data_key=6669c66d9609d8f9a1821e6928f3c584&map_content=global&show_future=1&name=gm-map-1&object_ids=174371529565047,174371529565046,174371529663274,174371529663195,174371529609792,174371529596380,174371529596379,174371529609791,174371529596378,174371529538729,174371529610349,174371529538728,174371529610348,174371529538726,174371529538724,174371529610352,174371529561088,174371529561087,174371529561086,174371529633478&sfid=174371529654519&sf_action=get_data&sf_data=results&_sf_s=some_keyword&post_date=12022018\\\\\\\\\\\\\\\\"\\\\"\"" style="\"position:" absolute;="" top:="" 0;="" left:="" width:="" 100%;="" height:="" border:="" none;="" overflow:="" hidden;\"=""><\/iframe><\/div><\/div>"}</iframe>
To isolate the issue, I eliminated possible interaction between the two plugins by directly accessing the search data and manually building a WordPress query to pass to GeoMashup:
// Get search parameters from other plugin $categories = $sf_current_query->get_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.