Title: Auto Loading Data while serach anything
Last modified: April 7, 2025

---

# Auto Loading Data while serach anything

 *  [niyati1129](https://wordpress.org/support/users/niyati1129/)
 * (@niyati1129)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/auto-loading-data-while-serach-anything/)
 * I have set the Store Locator page at:
   [https://spectaclehut.socialcandygroup.com/store-locator/](https://spectaclehut.socialcandygroup.com/store-locator/)
 * I’m passing the ZIP code via URL like this:
   [https://spectaclehut.socialcandygroup.com/store-locator/?wpsl-search-input=467360](https://spectaclehut.socialcandygroup.com/store-locator/?wpsl-search-input=467360)
 * When the page loads, it searches for stores based on the provided ZIP code as
   expected.
   However, after a few seconds, the page automatically reloads. I would
   like to **prevent this reload** if a search parameter (like the ZIP code) is 
   already present in the search box.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fauto-loading-data-while-serach-anything%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [farroyo](https://wordpress.org/support/users/farroyob/)
 * (@farroyob)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/auto-loading-data-while-serach-anything/#post-18404105)
 * Hi there, thanks for writing,
 * How did you exactly implement the functionality that captures the value of the
   GET parameter in the URL and triggers the search? Depending on how you did it,
   perhaps the issue is there.
 * I generally use a small code snippet like this to achieve that functionality:
 *     ```
       add_action( 'wp_footer', function () { ?>
   
       <script type='text/javascript'>
         // pure jquery snippet for loading the search term from GET parameter in the search field and clicking the button automatically
         jQuery( window ).load(function() {
           let searchParams = new URLSearchParams(window.location.search);
           if ( jQuery('#wpsl-search-input').val() != '' ) {
             jQuery('#wpsl-search-btn').trigger('click');
             console.log('search was triggered')            
           } 
       });
       </script>
   
       <?php } );
       ```
   
 * Please have a look and let us know if it is very different to your solution.
   
   Best regards,
 *  Thread Starter [niyati1129](https://wordpress.org/support/users/niyati1129/)
 * (@niyati1129)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/auto-loading-data-while-serach-anything/#post-18405177)
 * Hello, this is NOT working. I have added code in **store-locator.js** .
   With 
   this, I want the stores to be sorted alphabetically by default, and when a search
   is performed based on distance, the store listings should be sorted accordingly.
   For this I have added below code in my function.php , but it is not working .
 *     ```wp-block-code
       function custom_wpsl_sort_order( $sql, $data ) {  if ( isset( $data['autoload'] ) && $data['autoload'] == 1 ) {      // Default load: Sort alphabetically by store name      $sql .= " ORDER BY s.name ASC";  } else {      // On search: Sort by nearest distance      $sql .= " ORDER BY distance ASC";  }  return $sql;}add_filter( 'wpsl_sql_filter', 'custom_wpsl_sort_order', 10, 2 );
       ```
   
    -  This reply was modified 1 year, 1 month ago by [niyati1129](https://wordpress.org/support/users/niyati1129/).
    -  This reply was modified 1 year, 1 month ago by [niyati1129](https://wordpress.org/support/users/niyati1129/).
 *  [farroyo](https://wordpress.org/support/users/farroyob/)
 * (@farroyob)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/auto-loading-data-while-serach-anything/#post-18407361)
 * Hi again, thanks for getting back.
 * If you want to change the order of the search results, please have a look at 
   this article from our documentation: [change the order of the search results](https://wpstorelocator.co/document/change-search-results-order/).
 * > Hello, this is NOT working. I have added code in store-locator.js .
 * The code I sent you is meant to go inside the functions.php file, since it is
   injected into the page footer via the add_action function from WordPress. If 
   you use the code snippet I proposed in a separate js file, it may not work.
 * Last but not least, if you wish to modify the SQL query that is triggered when
   the plugin searches, it is best if you use our built-in wpsl_sql filter, here
   is the documentation: [wpsl_sql filter](https://wpstorelocator.co/document/wpsl_sql/).
 * Best regards,
    -  This reply was modified 1 year, 1 month ago by [farroyo](https://wordpress.org/support/users/farroyob/).

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

The topic ‘Auto Loading Data while serach anything’ 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/)

 * 3 replies
 * 2 participants
 * Last reply from: [farroyo](https://wordpress.org/support/users/farroyob/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/auto-loading-data-while-serach-anything/#post-18407361)
 * Status: not resolved