Skip Navigation

[Resolved] Sorting locations alphabetically unless an address is entered in Toolset Views

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 9 months ago.

Assisted by: Minesh.

Author
Posts
#2683523

Tell us what you are trying to do?

Display locations listed alphabetically when the user loads the page and switch to sorting by distance only if they enter an address. It's caused a lot of issues not being able to set a default sort order and we get a lot of complaints.

Is there any documentation that you are following?
I tried using the following code to override the behaviour but didn't do anything at all.

add_filter('wpv_filter_query', 'customize_toolset_sorting', 99, 3);
function customize_toolset_sorting($query_args, $view_settings, $view_id) {
if ($view_id == '549') {
if (empty($_GET['toolset_maps_distance_center'])) {
// No location provided, sort alphabetically by title
$query_args['orderby'] = 'title';
$query_args['order'] = 'ASC';
} else {
// User provided a location, use default config
}
}
return $query_args;
}

Is there a similar example that we can see?

What is the link to your site?
hidden link

#2683591

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share admin access details so I can check your current view settings and guide you accordingly.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#2683758

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems you have set different settings for the view on staging site as well as live site as I can see the posts are order by title it self already on staging site. If both view settings are different, can you please set the view setting on your staging site as per your production site so I can see the same results.

I've also moved the "wpv_filter_query" code you added to functions.php file of your theme to "Custom Code" section offered by Toolset:
- hidden link

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

Can you please share edit page screenshot of your view from your live/production site?

#2684476

Hi there,

I had left the filter sorting alphabetically but I can't seem to get your code working on the website. I tried using both the view sorting by alpha and seeing if it would sort by location when a location was provided, then the reverse setting the default sort to by distance from the location and alpha. The code doesn't seem to have any effect.

I also tested it using AJAX which was the current setting and full page refresh to see if that might be the issue. Could you confirm the settings you had it working with?

#2684522

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Rather my setup, as it should be clean setup, its important to test where you want to setup as it may be conflict with other plugins.

Please check the following link: hidden link

I've added the following code to "Custom Code" section offered by Toolset:
- hidden link

add_filter('wpv_filter_query', 'customize_toolset_sorting', 999, 3);
function customize_toolset_sorting($query_args, $view_settings, $view_id) {
if ($view_id == 549) {
		if (empty($_GET['toolset_maps_distance_center'])) {
			// No location provided, sort alphabetically by title
			$query_args['orderby'] = 'title';
			$query_args['order'] = 'ASC';
		} 
}
return $query_args;
}

Do you see it working as expected?