Skip Navigation

[Resolved] Sorting search results by distance from the closest to the most distant

This support ticket is created 2 years, 4 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 6 replies, has 2 voices.

Last updated by Waqar 2 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2231903

Dear Toolset support,

We are trying to do a few things and would like to confirm options with you:

1. We are trying to sort search results that have been already filtered by the distance feature of the Google maps integration from nearest to most distant of the entered values by the user.

Is there any documentation that you are following?
I found this documentation https://toolset.com/forums/topic/sorting-orderby-distance/page/2/ that is not working for me. Is there a way to add this as result sorting option for the user. And if not, is there a recommended plugin to do so?

2. What procedure would you recommend to bring all elements of the distance filter option into one line?

3. How can we delete the miles option in the distance field?

4. Sometimes we want to sort the search results alphabetically by last name. However, sometimes there seems to be a bug and the results are displayed in the wrong order. Is there a way to troubleshoot this?

5. We would like to add social media icons under a loop element that should display e.g. the facebook icon, when there is a facebook url entry in the post. Do you have a preset block of doing so? If not, which way would you recommend?

6. We want to display icons for example a house and next to it the address that is provided in a custom field of the post. Do you have a preset block of doing so? If not, which way would you recommend?

Thank you for your kind support.

#2232045

Waqar
Supporter

Languages: English (English )

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

Hi,

Thank you for contacting us and I'd be happy to assist.

In order to suggest the next steps for these points, I'll need to see how this view is currently set up.

Can you please share temporary admin login details, along with the link to the page with this view?

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

regards,
Waqar

#2237879

Waqar
Supporter

Languages: English (English )

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

Thank you for sharing the admin access.

The view on the page is created using the blocks-based editor, but ordering by distance search is only supported in the views created using a classic/legacy editor.

This means that you'll need to create a new view, using the classic/legacy editor. Please go to WP Admin -> Toolset -> Settings -> General and change the editing experience option to "Show both the legacy and Blocks interface and let me choose which to use for each item I build".

After that, you'll see the views management screen option in the Toolset admin menu (WP Admin -> Toolset -> Views), from where you can create a new view too.

You'll find the documentation on using the classic/legacy editor views at:
https://toolset.com/documentation/legacy-features/views-plugin/

I hope this helps and let me know if you face any difficulty in using the classic/legacy view editor.

Once your view with the results ordered by distance is ready, we'll move on to the next points.

#2239991

Dear Waqar,

Thank you for your reply. We have now changed the settings accordingly and we have introduced the view "Sort by distance" which is also already inserted into the previously named page.

Unfortunately, we have not found the possibility to order the search results by distance. Can you please help us on the page. Furthermore, these are the points that we would still like to sort out:

2. What procedure would you recommend to bring all elements of the distance filter option into one line?

3. How can we delete the miles option in the distance field?

4. Sometimes we want to sort the search results alphabetically by last name. However, sometimes there seems to be a bug and the results are displayed in the wrong order. Is there a way to troubleshoot this?

5. We would like to add social media icons under a loop element that should display e.g. the facebook icon, when there is a facebook url entry in the post. Do you have a preset block of doing so? If not, which way would you recommend?

6. We want to display icons for example a house and next to it the address that is provided in a custom field of the post. Do you have a preset block of doing so? If not, which way would you recommend?

Thank you for your kind assistance.

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-styling-distance-search-fields-to-show-inline/

#2240763

Waqar
Supporter

Languages: English (English )

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

Thanks for the update.

I've added the view "Sort by distance" on a new demo page so that it is more clear how it works, alone, without the other block's based view. You'll find this new page at:
hidden link

In the view's ordering settings, I selected the "Anschrift" so that the results are ordered by the distance from the searched location.
( screenshot: hidden link )

In the content template "Loop item in Sort by distance", which shows the loop items of this view, I included the "Heading" block to show the title of each "Ärzte" post.
( hidden link )

To show each Ärzte post's map marker, I also included the "wpv-map-marker" shortcode, linked to the "Anschrift" field:
( ref: https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker )


[wpv-map-marker map_id='map-14' marker_id='marker-[wpv-post-id]' marker_field='wpcf-anschrift'][/wpv-map-marker]

In this content template, you can add the content the same way as you added in the blocks-based view's loop item at the page "Arzt- & Kliniksuche".
( screenshot: hidden link )

4. Sometimes we want to sort the search results alphabetically by last name. However, sometimes there seems to be a bug and the results are displayed in the wrong order. Is there a way to troubleshoot this?

- In the classic/legacy views, you can use the "Sorting controls" button to insert the sorting controls in the "Search and Pagination" section.
( screenshot: hidden link )

You can add the sorting controls and in case, it is still not working as expected, you're welcome to share the steps to see the issue.

5. We would like to add social media icons under a loop element that should display e.g. the facebook icon, when there is a facebook url entry in the post. Do you have a preset block of doing so? If not, which way would you recommend?

- Yes, you can use the Toolset's "Button" block for this, which can show a button with a social icon and can be linked to the custom field for the dynamic URL.

6. We want to display icons for example a house and next to it the address that is provided in a custom field of the post. Do you have a preset block of doing so? If not, which way would you recommend?

- For this, you can either use the Toolset's "Button" block for icon or use the icon shortcode that you've used in the block's based view on the page "Arzt- & Kliniksuche".

I've created a separate ticket about the questions about the styling of the distance search fields and will follow up on that shortly.
( ref: https://toolset.com/forums/topic/split-styling-distance-search-fields-to-show-inline/ )

#2242337

Dear Waquar,

Thank you for the detailed explanation. It worked out to set up the distance-based ordering and to insert the buttons as adviced by you. When using the blocks editor for the search, we were able to add some dynamic contact information e.g. name, phone, and address to the markers on the map that displayed when clicking on each marker. Is this also possible with the calssic editor and if yes, how?

Furthermore, we would like to display the distance between the searched location and the post location at the end of the loop element - which we already do. We added the shortcode of the calculated distance and added the text "km away from your searched location". This now always displays in the loop element, even if the user has not entered a searched location. We tried to fix it with conditional formatting, but did not find a way to format it in a way that it only shows up, when the visitor used the distance filter. Can you please assist here?

In addition to that we want to have a conditional display of search fields. Let me explain this a little bit more:
Our first option in the search asks, if you want to search for a hospital or a private practice. If you choose hospital there should be another search filter popping up aksing you for which treatments you want to search. This field does not exist for a private practice. If the user chooses private practive a different field should come up. Is there a way to make this work?

Thank you.

#2243395

Waqar
Supporter

Languages: English (English )

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

Thanks for the update and glad that my message helped.

1. You can place any shortcode for the dynamic content between the map marker shortcode [wpv-map-marker]....[/wpv-map-marker] and it will show in the map marker's popup.

The following screenshots show step-by-step how you can insert the post's title shortcode [wpv-post-title]:

Screenshot 1: hidden link
Screenshot 2: hidden link
Screenshot 3: hidden link

You can also add the shortcodes directly using this shortcode reference:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/

2. To conditionally show the distance value text, only when the user has entered a central location for the search you can wrap it in a conditional statement like this:
( ref: https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/ )


[wpv-conditional if="( '[wpv-search-term param='toolset_maps_distance_center']' ne '' )"]
<p>[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-anschrift'] km Luftlinie von Ihrem eingegebenen Suchort entfernt.</p>
[/wpv-conditional]

The content from the conditional statement will only show if the URL parameter "toolset_maps_distance_center" has some value.

3. I'm afraid, conditional display option for the search fields is not available. For this, you'll have to include some custom script to show or hide the search field, based on the user selection.

For personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

Note: I'll be on vacation, so I won't be able to follow up on this ticket, until the start of next week. For timely assistance, I'll recommended starting a new ticket for each new question or concern.

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