• celin007

    (@celin007)


    Hi Tijmen,

    I would like to know if it is possible to change the order of result based on the store category (not by category filter)?

    I’ll explain in detail.
    I have 100 stores in 20 locations(location A, location B, location C etc. ).
    I have three categories for all the 100 stores – category 1-clothing and category 2-shoes, category 3 – watch.

    I would like to load clothing store first then shoes then watch store after that.

    This order should be the same if search for any location.
    If search for location C -> list clothing then shoes then watch store.
    If search for location D -> list clothing then shoes then watch store.

    The results should display by default and not by selecting any category filter.

    Kind regards
    Celin

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

    (@tijmensmit)

    This can be done, but only if your comfortable with code.

    If requires this filter, that allows you to access the data just before it’s returned. So you can loop over it, and check the terms data and sort it accordingly.

    How to include the terms data in the results is explained here.

    You also want to include this code to make sure the actual user input is included in the AJAX data, which you can use to determine is the user searched for location a or b.

    function wpsl_statistics_js_settings( $settings ) {
        
        $settings['collectStatistics'] = true;
        
        return $settings;
    }
    
    add_filter( 'wpsl_js_settings', 'wpsl_statistics_js_settings' );
    Thread Starter celin007

    (@celin007)

    Thanks Tijmen for the quick response.

    I included the below code in the function.php of the child theme. But the results remain the same, the results are not sorted based on category.

    add_filter( ‘wpsl_store_meta’, ‘custom_store_data’, 25, 25 );

    function custom_store_data( $store_meta, $store_id ) {

    $terms = wp_get_post_terms( $store_id, ‘wpsl_store_category’ );

    $store_meta[‘terms’] = ”;

    if ( $terms ) {
    if ( !is_wp_error( $terms ) ) {
    if ( count( $terms ) > 1 ) {
    $location_terms = array();

    foreach ( $terms as $term ) {
    $location_terms[] = $term->name;
    }

    $store_meta[‘terms’] = implode( ‘, ‘, $location_terms );
    } else {
    $store_meta[‘terms’] = $terms[0]->name;
    }
    }
    }

    return $store_meta;
    }

    Can you please advice me what values I need to pass in the function add_filter( ‘wpsl_store_meta’, ‘custom_store_data’, 10, 2); in place of 10 and 2. I have 100 stores so how can I pass the values for store ids?
    My category ids are 25,24 and 27 for clothing, shoes and watch stores.

    Thanks for your help.

    Kind regards
    Celin

    • This reply was modified 4 years ago by celin007.
    Thread Starter celin007

    (@celin007)

    Thanks Tijmen for the quick response.

    I included the below code in the function.php of the child theme. But the results remain the same, the results are not sorted based on category.

    add_filter( ‘wpsl_store_meta’, ‘custom_store_data’, 25, 25 );

    function custom_store_data( $store_meta, $store_id ) {

    $terms = wp_get_post_terms( $store_id, ‘wpsl_store_category’ );

    $store_meta[‘terms’] = ”;

    if ( $terms ) {
    if ( !is_wp_error( $terms ) ) {
    if ( count( $terms ) > 1 ) {
    $location_terms = array();

    foreach ( $terms as $term ) {
    $location_terms[] = $term->name;
    }

    $store_meta[‘terms’] = implode( ‘, ‘, $location_terms );
    } else {
    $store_meta[‘terms’] = $terms[0]->name;
    }
    }
    }

    return $store_meta;
    }

    Can you please advice me what values I need to pass in the function add_filter( ‘wpsl_store_meta’, ‘custom_store_data’, 10, 2); in place of 10 and 2. I have 100 stores so how can I pass the values for store ids?
    My category ids are 25,24 and 27 for clothing, shoes and watch stores.

    Thanks for your help.

    Kind regards
    Celin

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Including the terms data is only part of a few steps you need to take.

    You need to write code yourself to loop over there results with this filter, and compare the user input with whatever you want to sort the results on, and based on that change the sorting based on the terms values ( the category ids ).

    The user input itself is only accessible in $_REQUEST if you include the code snippet from this post.

    There’s unfortunately no easy solution for this.

    Thread Starter celin007

    (@celin007)

    Is it possible to include this as a premium addon for the plugin ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP Store Locator – change of result order based on category’ is closed to new replies.