Support » Plugin: WP Store Locator » How to add a search input button to my home page ?

  • Resolved leowebdev



    I’m using your excellent plugin and I would like to add a custom search to my home page — just a simple input and a button with “Locate your nearest store” that post the zipcode to location search page.

    There is any way to do it? further that, can I get the zipcode posted at url and use it to search the results?


Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Tijmen Smit


    This will be available in a widget later.

    If you know how to write code you could write it yourself by following these steps.

    – Add a search field that redirects to the store locator page with the search params in the url
    – On the store locator page grab the search parameters with js, and set it as the search value in the store locator search field. Search for ‘javascript get url parameter’ on Google for a some examples.
    – Then use to submit the store search

    tks bro! here is the code for somebody that may need it

    // zip code search (home page)
    $(function (){
    $(‘#wpsl-search-button1’).click(function() {
    var url = ‘/pages/location-search/?zip=’;
    var inputURL = $(‘#wpsl-search-input1’).val();
    window.location.href = url + inputURL;
    return false;

    // get parameter and post on location search
    $(function (){
    $.urlParam = function(name){
    var results = new RegExp(‘[\?&]’ + name + ‘=([^&#]*)’).exec(window.location.href);
    if (results==null) {
    return null;
    } else {
    return results[1] || 0;

    $.urlParam(‘zip’); // name

    // set the default value of a text input field

    // delay and click button

    Hi, thanks for posting your solution, but please, can you explain a little bit more?
    Where exactly did you put this code? And what code did you put in homepage? Did you used a form plugin or simply html code in the wordpress text editor?
    Thanks a lot!!!


    You should call the jquery in both pages — so paste it on your custom script field at wordpress and use plain html >> you just need an input and a button.

     <div class="wpsl-input"><input id="wpsl-search-input1" autocomplete="on" type="text" value=""></div>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code has now been permanently damaged by the forum’s parser.]

    Nice bit of kit, leowebdev, and works great until we get an official way to do this with a shortcode!

    The ONLY problem I had was that my “find a location” page where I have my shortcode triggering was always submitting NULL whenever I loaded it, and removing the “view all locations” after it submitted NULL!

    I fixed it by slightly changing your last bit of code to this:

    if ($.urlParam('zip')) {
                // set the default value of a text input field
                // delay and click button

    This way, when you go to your javascript doesn’t trigger – it will ONLY trigger when the urlParam is set.

    i’ve done the instructions, but doesn’t function,

    can you please guys explain little bit how to?

    Hi Eddt,

    I’ve encounter the problem you mentioned, but I have no idea where to put the code(solution) you stated in earlier post.

    I mean ..which place should I put the code?is it in style css? if so, which part of style css(e.g after –>body ?)I should put in the code you suggested?could you advice further?


    is there a way to search by the name of the store rather than scrolling???

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to add a search input button to my home page ?’ is closed to new replies.