I have a view that outputs locations. I have locations ordered by the address field ascending as a distance from URL parameter toolset_maps_distance_center
This is great for after a visitor uses the query to find the locations that are closest to them, but before the user queries by location I have all of the locations visible. The problem is that the locations appear random when you first visit the page as they're sorted by distance from the center of the map.
Is it possible to have the locations show in Alphabetical order before the user interacts with the query and then order by toolset_maps_distance_center after the user queries by their location?
You could use the wpv_filter_query API hook to modify the query sort setting, checking $_GET to see if the toolset_maps_distance_center parameter is provided, and if not switching to order by post title.
Hi Nigel - thanks for your response.
My understanding of Toolset / JS is only ok and I'm hoping you can help me with this.
I think if I set the view to be alphabetical by default, and then paste something like this in the JS it will reorder on search:
jQuery(document).ready(function($) {
if (isset($_GET['id'])){
$query->set('order', 'ASC');
$query->set('orderby', 'toolset_maps_distance_center');
}
}
Assuming this is on the right track I think I'm missing some of the $query->set parameters, such as how do I tell it to sort by the address field in the orderby section?
Hello. Thank you for contacting the Toolset support.
You can not mix Server side script (PHP) and Javascript that runs of frontend. What you are doing is totally wrong.
As I understand - you want to display the view results alphabetically when page is loaded first time and when user change any filter you want to order view results by toolset_maps_distance_center - is that correct? If yes:
Can you please share on what page you added your view and share admin access details and let me review your structure first and then I'll be able to guide you with the right direciton.
*** Please make a FULL BACKUP of your database and website.***
Additionally - I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.