Hi,
Thank you for contacting us and I'd be happy to assist.
1. The ordering that you're trying to achieve is not possible using the view's ordering settings, so it will require some custom code.
The "wpv_filter_query" hook can be used to set the ordering by 'title', when the distance search is not used, for example:
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
// if distance search is not set
if(empty($_GET['toolset_maps_distance_radius'])) {
// set order by title
$query_args['orderby'] = 'title';
$query_args['order'] = 'ASC';
}
}
return $query_args;
}
Note: Please replace '12345' with the actual ID of your view.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
When the page will load, the results will be ordered by the title, but, once the distance search will be used, the results will show, ordered by the distance.
Note: Please make sure that the view's ordering settings are set to order by distance, as shown in the attached example screenshot.
2. To conditionally show the distance from the searched location, you can use the "toolset-maps-distance-value" shortcode inside the conditional statement like this:
( ref: https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#toolset-maps-distance-value )
[wpv-conditional if="( '[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-product-address']' ne '' )"]
Distance from search location:<br>[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-product-address'] km.
[/wpv-conditional]
Note: You'll replace "product-address" with the actual slug of your address field and please also add "toolset-maps-distance-value" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar