Viewing 3 replies - 1 through 3 (of 3 total)
  • 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

    (@niyati1129)

    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 .

    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.
    • This reply was modified 1 year, 1 month ago by niyati1129.

    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.

    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.

    Best regards,

    • This reply was modified 1 year, 1 month ago by farroyo.
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Auto Loading Data while serach anything’ is closed to new replies.