Skip Navigation

[Resolved] Order by Distance Not Working Using Legacy View And Address Fields

This support ticket is created 2 years, 2 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/Karachi (GMT+05:00)

This topic contains 30 replies, has 3 voices.

Last updated by Waqar 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2277823
Screen Shot 2022-01-27 at 11.10.25 AM.png
Screen Shot 2022-01-27 at 11.04.33 AM.png

Tell us what you are trying to do?
List nearest cities of custom post types.

I have State/City Taxonomy pages (hidden link)

That have term type field: [si-addy-city-state] which is an Address field that in this example contains: Appleton, Wisconsin, USA
That have term type field: [parent_term_info output='name'] which plain text returns: Wisconsin

It's not possible to run a distance view for taxonomies, I built a workaround by creating a custom post type 'Individual Cities', which contain the permalink to the matching taxonomies, and geographic data, so then I can sort by distance (mild workaround).

On the taxonomy page in this example, I call a view of those 'Individual City' with the attached screenshot view, with this code (some excess due to trial and error):
[wpv-view name='cities-near-input-city-list' mapcenter='[types termmeta='si-addy-city-state']' from_center='[types termmeta='si-addy-city-state']' parentstate='[parent_term_info output='name']' limit='8']

The goal is to list the 8 cities nearest to 'Appleton, Wisconsin, USA', sorted by closest to furthest.

Ordering: I have done URL parameter: mapcenter, toolset_maps_distance_center, and the above shortcodes.

The 'parentstate' filter is used to keep the query shorter, and also to lock the results by state (this works)

The mapcenter shortcode attribute for 20mi distance works, so it's receiving the right 'Appleton, Wisconsin, USA' and running it through the 'Individual City' custom posts. It definitely finds the nearby cities, but does not order by distance.

Ordering by distance does not work, regardless of any attempts to debug as listed above, it only will display alphabetical, which is not ideal at all lol.

I have attached what the DB query looks like on the front end, seems confused about something but this is above my skill level.

Is there any documentation that you are following?
The 'standard' methods, other blog posts, archived tickets (such as: https://toolset.com/forums/topic/sorting-views-by-distance-to-current-post-geolocation/#post-1140488) I have tried this method and added the code to functions and experimented to no results.

What is the link to your site?
hidden link

#2278135

([toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-ws-sc-addy-city-state-usa' unit='mi'] Miles)

within the loop for the view output "cities-near-input-city-list" (the output that is working with the custom post type 'individual city') returns a blank every time as well, regardless of how I configure it

#2278263
distance-order2.jpg

Hello,

In your screenshot:
https://toolset.com/wp-content/uploads/2022/01/2277823-Screen_Shot_2022_01_27_at_11.04.33_AM.png
in section "Ordering", it is option "URL parameter", so it won't be able to sort the result by shortcode attribute "mapcenter"

And there isn't such a built-in feature to sort the result by distance of shortcode attribute "mapcenter", see my screenshot distance-order2.JPG

You can add a feature request, our developers will evaluate it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#2278497

What?

#2278509

If you read my ticket I have tried a variation of things to get it to sort by distance (two address fields), the screenshots are not the only attempts.

From OP: Ordering: I have done URL parameter: mapcenter, toolset_maps_distance_center, and the above shortcodes.

This includes by URL parameter, as well as the linked ticket method.

#2278511
3CBE2B9C-8B10-4180-9F55-46744F05793E.png

Ordering does not work.

Filter does work.

#2279835

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for sharing these details.

Luo is on vacation this week, so I'll be following up on this ticket.

To troubleshoot this, I'll need to see exactly how this view and other related elements are set up on your website.

Can you please share temporary admin login details, in reply to this message?

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2280749

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The admin access details worked, thank you.

I'm currently performing some tests with a similar setup on my test website and will share my findings, accordingly.

Thank you for your patience.

#2280981

On the center page, I have it working, as stated above, same view.

So on the archive page, I created a new view, to wrap the working view in, basically pretending it's a center. I named it "Cities - Parent for Near By List" and put it right under the non working view on the city archive page.

I added a 'show the current post name' to that view, just to make sure it's pulling from the current taxonomy, which it is, then it lists out the cities (using the view that works on the center pages), and even with that it's not sorting by distance, still sorting alphabetical. In theory, this should 'fix' it, right?

As it's loading the post, then displaying the view from the post, lol?

#2282707

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting, while I looked into the setup.

I noticed that in the view "Cities - Near INPUT City - List", the ordering by distance is working as expected if the target location is passed in the URL parameter "toolset_maps_distance_center".

For example:
hidden link
( value for the "ws-nap-address-full" is "607 W 7th St, Appleton, WI 54911" )

Note: I've added the distance shortcode at the end of the result titles to make it more clear: screenshot: hidden link )

This means that the ordering settings are working as intended. However, as Luo pointed out earlier, the order settings can't be linked to the shortcode attribute as there are only 3 options "Fixed", "Visitor location" and "URL parameter". In your case, you needed this to work with the value coming from the "ws-nap-address-full" custom field, passed through the shortcode attribute, which isn't supported.

One workaround can be to let the result generate in alphabetical order, but, then use some custom script, that can order all the results in the list, based on the distance value, in ascending order. Let me know if this sounds like a workable solution.

#2283895

The view does work and sort properly on a custom post, as in the bottom right corner here: hidden link

On the taxonomy archive page, it does not work, but it should, if I embed the working view, within in a view, so it loads on the taxonomy archive page 'as if' it is the custom post template page. But this does not work.

Can you explain why it works on the custom post page (URL above), perfectly 10000% fine, even though it shouldnt based on the response you gave, but does NOT work on the taxonomy archive page?

#2286715

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting, while I performed some further investigation and testing.

Your observation is correct and the same view (Cities - Near INPUT City - List) is sorting the results by distance, on the mentioned single "Center" post page, but, not when used in the archive.

During testing on my website with a similar setup, I'm getting the same ordering behavior as in your website's archive. To debug deeper into why this is working in your website's single "Center" post pages, I'll need your permission to download a clone/snapshot of your website.

This will help us in troubleshooting this, without affecting the actual website.

#2289777

Ok I'll get that together, what's the plugin you guys prefer for this?

#2291803

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

We recommend the 'Duplicator' plugin ( https://wordpress.org/plugins/duplicator/ ) for sharing the website's clone/snapshot.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

Some servers don't support/allow this plugin, for which the 'All-in-One WP Migration' plugin ( https://wordpress.org/plugins/all-in-one-wp-migration/ ) can be used instead.

Note: Since I already have the website's admin access, I can download the clone/snapshot directly from the website.

#2303403

I am working on this now and will update.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.