• Let me just first off extend my appreciation for this plugin. It is absolutely amazing.

    I have a feeling that this may be able to be answered by someone other than the developer. I am not exactly a novice to PHP, so I’m struggling. I’ve spent about four hours trying to figure out what I’m doing wrong…

    Here is my goal — use a GET variable to modify the select statement that pulls the stores for the map

    I’m under the presumption that the query to pull the stores for the map is in plugins/wp-store-locator/frontend/wpsl-ajax-functions.php starting at line 49.

    In the query, where it says ‘WHERE active = 1’, I want to add in a variable that I’ve modified so that it only pull stores of a certain wpsl_id.

    For some reason, no matter what I do, I cannot pull $_GET[‘stores’] and add it into the query. It’s as if it does not see the GET variable.

    Ex. This (and a number of variants) does not work —
    “SELECT *, ( $distance_unit * acos( cos( radians( %s ) ) * cos( radians( lat ) ) * cos( radians( lng ) – radians( %s ) ) + sin( radians( %s ) ) * sin( radians( lat ) ) ) )
    AS distance FROM $wpdb->wpsl_stores WHERE active = 1 && wpsl_id = “. $_GET[‘stores’] .””

    What am I missing? I feel it’s something trivial. Also, the variable is getting passed to the script. I can echo it near the beginning (but not from within the wpsl_store_search function).

    Any help would be much appreciated.

    Thanks!

    https://www.ads-software.com/plugins/wp-store-locator/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter brm051

    (@brm051)

    Plugin Author Tijmen Smit

    (@tijmensmit)

    I think you should modify the $sql_part and $placeholder instead of modifying the query directly.

    Untested.

    $sql_part = ' AND wpsl_id = %d HAVING distance < %d ORDER BY distance LIMIT 0, %d';
    $placeholders = array(
        $_GET["lat"],
        $_GET["lng"],
        $_GET["lat"],
        $_GET['stores'],
        $_GET["radius"],
        $max_results
    );

    Also make it print the wpdb errors and the last query, to make sure the query itself is correct. https://codex.www.ads-software.com/Class_Reference/wpdb#Show_and_Hide_SQL_Errors

    Thread Starter brm051

    (@brm051)

    Thank you very much for your help Tijmen, I will report back.

    -Ben

    Thread Starter brm051

    (@brm051)

    Hi Tijmen,

    No luck. I’ve also tried it without the get variable (ie. … AND wpsl_id = 1 HAVING …) and it still does not pull anything. The loading wheel just keeps spinning.

    I also copied the core of that code into another file and ran it with wpdb->showerrors (nothing will echo to the actual map page), and there were no errors.

    I’m stumped and giving up. Too much time spent on this. Thanks for your help and for the plugin. I will definitely still be using it for a store locator in general, but will need to find another solution for the display of particular stores.

    -Ben

    Plugin Author Tijmen Smit

    (@tijmensmit)

    One last thing you can try is to enable wp_debug in the wp-config.php, then install getfirebug.com so that when you load the page and the Ajax request is made you can see php errors/warnings in the debug console.

    You can access the console in Firebug under F12 and see any errors.

    Thread Starter brm051

    (@brm051)

    ok, I did enable the debug early in the process looking for a solution ??

    I did not realize it would come up in firefox. I will investigate.

    Thanks!

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Normally errors would show up on your screen, but it works different with Ajax request. They are made in the background, so the page never reloads and never outputs the error.

    So when you want to debug Ajax request, something like Firebug is needed. Chrome, IE and other browsers have other web dev tools where you can view debug data in the console.

    Thread Starter brm051

    (@brm051)

    No errors.

    I’m going to go another route, perhaps hiding the GET variable in the form where it asks for location / distance / results, then sending it when the search button is hit.

    I appreciate your help with this, but I don’t want to waste any more of your time trying to find a resolution. Perhaps in the next release, you could add something into the shortcode in which only certain stores were displayed? For example, [wpsl stores=”1,4,6,10″].

    Thanks again, Tijmen. Excellent work with this plugin regardless of what I’m trying to do here.

    -Ben

    Plugin Author Tijmen Smit

    (@tijmensmit)

    If you add this after the query runs, does the query itself look okay with all the correct values?

    $wpdb->last_query

    Thread Starter brm051

    (@brm051)

    I’m not sure how to get insight from that command (last_query), however I was able to look in the console and it is returning the appropriate result. It seems as though the container with the store information and the map area are not updating to display it.

    I appreciate your help with all of this Tijmen, if you are out of ideas or have more pressing issues to tend to, please do not feel as though you need to continue walking me through this.

    In the console, I am getting this notice, however I believe it is unrelated —
    <b>Notice</b>: ob_end_flush() [ref.outcontrol]: failed to delete buffer zlib output compression. in <b>/myhosting/site/wp-includes/functions.php</b> on line <b>3092</b>

    Thanks!

    Thread Starter brm051

    (@brm051)

    One interesting thing that I did notice, a bit unrelated, but perhaps it might save yourself a headache in the future —

    I gave up on everything above and just dumped a fresh copy of the plugin folder into the plugins dir.

    So I went to the map and put in a US ZIP code (I also tried this with geolocation) and the map came up as usual, nothing out of the ordinary.

    With that information still in the input box, I tried to narrow it further by selecting a lesser radius.

    Nothing happened on submit, just loading wheel.

    Looked in the debugger and still saw that ‘notice’ about ob_flush, so I went and disabled debugging in wp-config.

    Map started working correctly again.

    Just thought this is something you might like to know.

    Thanks Tijmen,

    -Ben

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Limiting Map Results to List of wpsl_id's’ is closed to new replies.