How can I add a sort by distance to the view shortcode?

Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
As a base from what distance you want to sort the results, is it from the parent location address as a base to sort it?
Hi Minesh. That's correct.
So for this page the Auburn Listing should appear second as the distance is 1.1 from the current_page location.
lien caché
If possible I would also like to have 'Verified' items that will automatically sort to the top of the pile, and ignore distance.
To set the distance order by, I've set the ordering section to order by the lat-long field ASC with Distance from "fixed" source.
=> lien caché
Screenshot: lien caché
Then to set the fixed distance as your current posts lat-long value, I've added the following filter to "Custom Code" section offered by Toolset:
=> lien caché
add_filter( 'wpv_view_settings', 'func_set_distance_orderby_address', 10, 2 );
function func_set_distance_orderby_address( $view_settings, $view_id ) {
if ( $view_id == 88 ) {
global $post;
$view_settings['distance_order']['center'] = get_post_meta($post->ID,'wpcf-post-lat-long',true);
}
return $view_settings;
}
More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset
Can you please confirm it works as expected now.