Skip Navigation

[Resolved] Sort by Distance

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 21 replies, has 2 voices.

Last updated by Luo Yang 2 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2380755

Hey,

You've still got access to my site, can you please set up the new view? I've never used your Legacy Editor and I know next-to-nothing about HTML; I'll just make it worse and this ticket will continue forever.

Please set it up the same as I current have (in the blocks editor) but with "Sort By: Distance" as the default option (but can be changed to alphabetically by name and/or by suburb; if I have the distance one set up I won't need "By post ID" any more)

If it makes it easier, if you just duplicate the current page but switch out the new (legacy) view, I can sort out the redirects in my own time without disrupting the current flow of things.

#2381077

The problem is you are using the "sortby" dropdown in the frontend custom search form, it will override the default sortby settings.

I have done below modifications in your website:
1) Dashboard-> Toolset-> Settings-> Custom codes,
Deactivate item "sortbydistance"
2) Edit your theme file "functions.php":
hidden link
line 124~142, add below codes:

add_filter( 'wpv_view_settings', 'ts_view_settings', 101, 2 );
function ts_view_settings( $view_settings, $view_id ){

    $address_field_slug = 'suburb-of-offender'; // Edit 

    if ( $view_id == 1927 ) // Edit View ID
    {
        $view_settings['order_by'] = "field-wpcf-$address_field_slug";
        $view_settings['orderby_as'] = 'DISTANCE';
        $view_settings['order'] = 'ASC';
        $view_settings['distance_order'] = array(
            'source'        => 'url_parameter',
            'center'        => '',
            'url_parameter' => 'toolset_maps_distance_center'
        );
    }

    return $view_settings;
}

3) Edit the problem page:
hidden link
Find and select the view block, in the block setting panel, section "Ordering", option "Sort By", choose the option "Field - Suburb of Offender"

Test it in frontend:
hidden link
1) Fill value "Sydney NSW, Australia" in the location field
2) Sort by, choose option "Suburb", it works fine:
hidden link

Please check if it is fixed, thanks

#2381169
GTMetrix report 2.PNG
GTMetrix report.PNG

Thank you. It IS working, and I appreciate the effort, but the site runs like absolute garbage now.

I had to run a GTMetrix test to see if it was my home internet or the site itself. (See 1st attached image) - Coincidentally I ran this same test today (I was in a conversation about Perfmatters and we ran GTMetrix tests to compare sites) and I was getting an A - 100% - 90% - 620ms - 2ms - 0.01 (Or something very close to that)

I waited 10 minutes and ran it a 2nd time. (See 2nd attached image)

I'll keep an eye on it for another day or so and see if it sorts itself out.

Also; what will happen when I update my theme? Will it clear the code? (I don't know how themes and child themes work)

Lastly, as I asked before, is there a way we can have it so the 3 options for sorting are Distance (default), Name (alphabetically) and Suburb (alphabetically)? It seems that the way you've done it overwrites sorting by suburb alphabetically.

Also, thank you for all this so far; I'm still flabbergasted that "Sort By: Distance" is not already built into Toolset as it's really the main 'default' option that makes sense when you can geosearch; I can think of few instances where you'd want to geosearch with a map and sort by anything else.

#2381757

Q1) For the new issues, It is nothing about the custom PHP codes, I suggest you try these:
1) Remove the custom PHP codes from your theme file "functions.php"
2) run the GTMetrix test, and test again, if you get the same results, you will need to check other parts of your website

Q2) There isn't such kind of built-in feature within Toolset plugins, you can add a feature request for it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Our developers will evaluate it

#2381805

I'm not sure what you're referring to with your "Q2".

Is it possible for me to have the 3 sorting options (Distance, Name and Suburb) or is just the 2 that you got for me (Distance and Name)?

#2381807

Oh, and you didn't answer re: child themes.

#2384375

Q2) Yes, I am talking about sorting options "Distance"
Q3) child themes.
You can try to move the custom codes into Toolset custom codes, and test again, since the website credentials isn't valid any more, I did not test it in your website