Title: Search by Store
Last modified: August 30, 2016

---

# Search by Store

 *  [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/)
 * I applied this plugin into my website and I happy with the function that provided.
 * Right now I finding a way to filter out the result by Store when I type store
   name into the input.
 *     ```
       function codeStore( infoWindow ) {
           var latLng,
       		autoLoad = false,
       		keepStartMarker = false,
       		store_name = $( "#wpsl-search-input" ).val();
   
           geocoder.geocode( { 'address': store_name}, function( response, status ) {
       		if ( status == google.maps.GeocoderStatus.OK ) {
       			latLng = response[0].geometry.location;
   
       			/* Remove any previous markers and add a new one */
       			deleteOverlays( keepStartMarker );
       			addMarker( latLng, 0, '', true, infoWindow ); // This marker is the 'start location' marker. With a storeId of 0, no name and is draggable
   
       			/* Try to find stores that match the radius, location criteria */
       			findStoreLocations( latLng, resetMap, autoLoad, infoWindow );
       		} else {
       			geocodeErrors( status );
       		}
           });
       }
       ```
   
 * Any solution on this ?
 * [https://wordpress.org/plugins/wp-store-locator/](https://wordpress.org/plugins/wp-store-locator/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Author [Tijmen Smit](https://wordpress.org/support/users/tijmensmit/)
 * (@tijmensmit)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567683)
 * You just want to search on store names, instead of location names?
 *  Thread Starter [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567702)
 * Hi Tijmen,
 * Yes.
 * I found 2 problem now.
 * 1) I realize something that before this plugin is updated, i can simple retrieve
   State column from each record to the drop down. But now I having problem on retrieve
   the state column as an option for my drop down.
 * 2) I can’t find a solution that only show the result based on the store name 
   that I insert into the input field.
 * Thanks for the assist.
 *  Plugin Author [Tijmen Smit](https://wordpress.org/support/users/tijmensmit/)
 * (@tijmensmit)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567801)
 * I don’t have time to get into details, but you have to get the [unique post meta values](https://www.google.nl/search?q=wordpress+select+unique+post+meta&ie=utf-8&oe=utf-8&gws_rd=cr&ei=tAwBVtXKDemsygP0_7qQBA)
   to get a list of states.
 * For the other issue, you have to modify wpsl-gmap.js ( the wpsl-gmap.min.js is
   the one used on the frontend, so you have to minify the modifications yourself
   on a site like [http://javascript-minifier.com/](http://javascript-minifier.com/))
   to include the value from the input field in the AJAX request. The data for the
   AJAX request is put together in the _function makeAjaxRequest_. Then use that
   value in the find_nearby_locations() function in the class-frontend.php.
 * There is a filter called ‘wpsl_sql’ that allows you to modify the sql query. 
   In your case you don’t want it to calculate the distance based on the latlng,
   but just search for matching store names. This [post](http://stackoverflow.com/questions/7973121/wordpress-sql-post-title-search)
   should help you get started, do change the post type to ‘wpsl_stores’.
 *  Thread Starter [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567858)
 * Hi Tijmen, I have been trying to find the solution on search by Store name in
   my query.
 * I realize when I apply “LIKE” at the end of the query, it show no result.
 * But I did try the query in my database. It able to get the record.
 * Can you assist me on this ?
 *     ```
       $sql = apply_filters( 'wpsl_sql',
                              "SELECT posts.post_title AS store,
                                      post_state.meta_value AS state,
                                      post_lat.meta_value AS lat,
                                      post_lng.meta_value AS lng,
                                      posts.ID,
                                      ( %d * acos( cos( radians( %s ) ) * cos( radians( post_lat.meta_value ) ) * cos( radians( post_lng.meta_value ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( post_lat.meta_value ) ) ) )
                                       AS distance
                                 FROM $wpdb->terms AS terms
                                 INNER JOIN $wpdb->term_taxonomy AS term_taxanomy ON term_taxanomy.term_id = terms.term_id
                                 INNER JOIN $wpdb->term_relationships AS term_relationships ON term_relationships.term_taxonomy_id = term_taxanomy.term_taxonomy_id
                                 INNER JOIN $wpdb->posts AS posts ON posts.ID = term_relationships.object_id
                           INNER JOIN $wpdb->postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat'
                           INNER JOIN $wpdb->postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng'
                           INNER JOIN $wpdb->postmeta AS post_state ON post_state.post_id = posts.ID AND post_state.meta_key = 'wpsl_state'
                               /*$cat_filter*/
                                WHERE posts.post_type = 'wpsl_stores'
                                  AND posts.post_status = 'publish'
                                  AND post_state.meta_value='$states'
                                  AND terms.term_id='8'
                                  AND posts.post_title LIKE '%$searchvalues%'"
       ```
   
 *  Thread Starter [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567864)
 * Hi Tijmen..can you assist me on this ? Based on the query provide above..I could.
   it get the result based on the $searchvalues..
    If any mistake on my code..please
   advise me thanks
 *  Thread Starter [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567866)
 * Hi Tijmen,
 * I did try on the post the you suggested for me and apply to the SQL to search
   for the matches store name.
 *     ```
       $sql = apply_filters( 'wpsl_sql',
                                  "SELECT posts.post_title AS store,
                                          post_state.meta_value AS state,
                                          posts.ID,
                                          ( %d * acos( cos( radians( %s ) ) * cos( radians( post_lat.meta_value ) ) * cos( radians( post_lng.meta_value ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( post_lat.meta_value ) ) ) )
                                           AS distance
                                     FROM $wpdb->terms AS terms
                                     INNER JOIN $wpdb->term_taxonomy AS term_taxanomy ON term_taxanomy.term_id = terms.term_id
                                     INNER JOIN $wpdb->term_relationships AS term_relationships ON term_relationships.term_taxonomy_id = term_taxanomy.term_taxonomy_id
                                     INNER JOIN $wpdb->posts AS posts ON posts.ID = term_relationships.object_id
                               INNER JOIN $wpdb->postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat'
                               INNER JOIN $wpdb->postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng'
                               INNER JOIN $wpdb->postmeta AS post_state ON post_state.post_id = posts.ID AND post_state.meta_key = 'wpsl_state'
                                   $cat_filter
                                    WHERE posts.post_type = 'wpsl_stores'
                                      AND posts.post_status = 'publish'
                                      AND post_state.meta_value='$states'
                                      AND terms.term_id='8' AND posts.post_title LIKE '%CAR CARE%'
                                  "
                           );
       ```
   
 * It show no result. But it show have record when execute this code is my database
   sql.
 * I might urgent need your help. Please assist me on this.
 * Appreciate much for your help.
 *  Plugin Author [Tijmen Smit](https://wordpress.org/support/users/tijmensmit/)
 * (@tijmensmit)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567867)
 * Did you check for [errors](https://codex.wordpress.org/Class_Reference/wpdb#Show_and_Hide_SQL_Errors)?
 * Does this code show all the values in the correct place, so the searched value
   is a actually included in the query?
 *     ```
       echo $wpdb->last_query
       ```
   
 * Searching for the store name, without the code for the wpsl_state does work fine?
 *  Thread Starter [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567868)
 * Hi Tijmen,
 * I did try see are the query get result or not in the code below
 *     ```
       $stores = $wpdb->get_results( $wpdb->prepare( $sql, $placeholder_values ) );
   
                   if ( $stores  ) {
                       //echo $searchvalues;
                       $store_data = apply_filters( 'wpsl_store_data', $this->get_store_meta_data( $stores ) );
                   }
                   else{
                       echo "No result";
                   }
       ```
   
 * It show “No result”. Yes. Without wpsl_state the code also not work fine.
 *  [briankeith68](https://wordpress.org/support/users/briankeith68/)
 * (@briankeith68)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567869)
 * I modified 4 files to make this happen.
    wpsl-ajax-functions.php, wpsl-gmap.js,
   templates/default.php and optional styles.css
 * Its a hardcoded solution instead of hooks. Works great. Great plugin.
 *  [briankeith68](https://wordpress.org/support/users/briankeith68/)
 * (@briankeith68)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567870)
 * Your LIKE condition will work but you must escape the % by using two %%.
    AND
   posts.post_title LIKE ‘%%CAR CARE%%’
 *  Thread Starter [William1234](https://wordpress.org/support/users/william1234/)
 * (@william1234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567871)
 * Hi Briankeith68,
 * I still can’t get the result.
 * Example what is did “AND posts.post_title LIKE ‘%$searchVariable%'”
 * Where the $searchVariable will get the input value from user.
 *  [briankeith68](https://wordpress.org/support/users/briankeith68/)
 * (@briankeith68)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567872)
 * Did you try “AND posts.post_title LIKE ‘%%$searchVariable%%'”
    Note the two %
 *  [netelie](https://wordpress.org/support/users/netelie/)
 * (@netelie)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567927)
 * Firstly,
 * what a greattttt plugin here by Tijmen.
 * So, regarding to this topic
 * Briankeith68, could you please share with us the code and how you did it?
 * I’m not a programmer but i know just enough for a designer.
 * thanks in advance!!

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Search by Store’ is closed to new replies.

 * ![](https://ps.w.org/wp-store-locator/assets/icon-256x256.jpg?rev=1007784)
 * [WP Store Locator](https://wordpress.org/plugins/wp-store-locator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-store-locator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-store-locator/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-store-locator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-store-locator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-store-locator/reviews/)

 * 13 replies
 * 4 participants
 * Last reply from: [netelie](https://wordpress.org/support/users/netelie/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/search-by-store/#post-6567927)
 * Status: not resolved