Skip Navigation

[Resolved] Legacy view

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 7 replies, has 2 voices.

Last updated by Timothy 1 year, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2533561

I have a cpt Places, each with an address field, and am trying to display the closest 3 Place to this cpt in a section on my page "Other Bars Closest to..." that displays a legacy view ordering by the cpts address field, "as a distance from" toolset_maps_distance_center

You can see this view being displayed at the bottom of this page:

hidden link

If you put the address of this place into the address search field "Nguyen Dinh Chieu 69 Mũi Né, Bình Thuận " it produces the desired results. So essentially I just need this field pre-populated with the current cpts address field and for it to run on page load.

This seems like it should be an easy way to do this because it's such a useful feature and I can get so close with my current configuration.

#2535167

Waqar
Supporter

Languages: English (English )

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

Hi,

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

To order/sort the view's results based on the location from the current post's address field, you'll need some custom code.

You'll find the steps and the code example for the same, in this forum ticket:
https://toolset.com/forums/topic/sorting-views-by-distance-to-current-post-geolocation/#post-1140488

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2535237

Sorry, I should have mentioned that I previously did follow the ticket you mentioned, and that is how I got this far. I have added that code to my functions file and I have the Ordering setup like the screenshot from that ticket, and added this to my template:

[wpv-view name="related-listings-by-distance-closest" from_center="[wpv-post-field name='wpcf-location-address']"]

But it doesn't seem to work.

Tim

#2536279

Waqar
Supporter

Languages: English (English )

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

Thanks for writing back.

Can you please share the temporary admin login details, so that I can see how this view is set up in the admin area?

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

#2537981

Waqar
Supporter

Languages: English (English )

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

Thank you for sharing the access details.

After reviewing the set up, I've added the following changes to the view "Related Listings by Distance - Closest", which seems to do the trick:

1. In the view's "Output Editor", I've added the following hidden HTML and shortcode, to include the address from the "location-address" field:


<span id="current-listing-address" style="display:none;">[types field='location-address'][/types]</span>

2. Next, in the view's "JS editor", I've included the following custom script, that reads the address from the hidden container from step 1, fills it in the location center search field and then triggers the search automatically, when the page loading completes:


jQuery(document).ready(function( $ ) {
	var currentAddress = $('span#current-listing-address').text();
	if(currentAddress.length != 0) {
		$('input#toolset-maps-distance-center').val(currentAddress);
		$('input#toolset-maps-distance-center').trigger('change');
	}
});

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2538317

Awesome thanks. This does work to populate the search field, but it's not triggering the search automatically. You can see that when you click into the address field and press enter, then the closest locations appear(you can see with the km numbers)

hidden link

$('input#toolset-maps-distance-center').trigger('change');

Tim

#2538611

Waqar
Supporter

Languages: English (English )

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

Thanks for writing back and I've made a slight change to the script.

Instead, of triggering the 'change' event to the distance center search field, it is targeting the distance value field:


jQuery(document).ready(function( $ ) {
	var currentAddress = $('span#current-listing-address').text();
	if(currentAddress.length != 0) {
		$('input#toolset-maps-distance-center').val(currentAddress);
		$('input#toolset-maps-distance-value').trigger('change');
	}
});

Can you please test the page now, after clearing all involved caches?

#2539329

My issue is resolved now. Thank you!

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