To sort the results by distance in (DESC) order I've again adjusted the code as given under:
add_filter('wpv_filter_query_post_process', 'func_include_national_posts', 10, 2);
function func_include_national_posts($query, $settings) {
if ($settings['view_id'] == 1546) {
if(isset($_GET['wpv-wpcf-national-broker']) and $_GET['wpv-wpcf-national-broker']=='National Broker'){
$without_found_ids = $national_posts = $without_national_posts = array();
$qry_args = $query->query['meta_query'];
$without_national_posts = get_view_query_results(4144);
$national_posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'expert',
'meta_query' => $qry_args ));
$merge = array_merge( $query->posts, $without_national_posts,$national_posts);
$result = $distance = array();
foreach($merge as $k=>$v):
$distance[$v->ID] = do_shortcode("[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-address' unit='mi' postmeta_id='".$v->ID."']");
$result[$v->ID] = $v;
endforeach;
/// sorting by deistance
arsort($distance);
foreach($distance as $k=>$v):
$distance[$k] = $result[$k];
endforeach;
$result = $distance;
$query->posts = array_values($result);
$query->found_posts = count($result);
}
}
return $query;
}
For my information:
Can you tell me how I can NOT show the 'National Brokers' on the map should I choose not to?
==>
Yes, thats correct. You should not select'National Brokers'.
Is there a way I can put the heading 'National Brokers' above the 'national brokers' results?
==>
Yes, done. I've added the conditional block to your following view:
- lien caché
How can I remove the [toolset-maps-distance-value] from the National Brokers results?
==>
I've added the following conditional statement to hide the distance value for the "National Brokers":
[wpv-conditional if="( '[types field='national-broker' output='raw'][/types]' eq '' )"]
[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-address' unit='mi'] miles
[/wpv-conditional]
Lastly:
Eventually I will need to implement this on the production site, can you assist or list out for me the changes you have made on this staging site?
==>
1. You will have to apply the code I shared with the same view ID you are displaying that is added to the "Custom Code" section.
2. You will have to create the following view as well and make sure with the code snippet you adjust the view ID with the get_view_query_results() function:
- lien caché
3. you will have to add the conditoinal statements that I added to your following view:
- lien caché
3.1 To hide distance value for "National Brokers":
[wpv-conditional if="( '[types field='national-broker' output='raw'][/types]' eq '' )"]
[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-address' unit='mi'] miles
[/wpv-conditional]
3.2 And conditional block to display heading 'National Brokers' for national broker posts.
Glad to know that the solution I shared help you to resolve your issue.
As per our support policy - we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery. May I kindly ask you to open a new ticket with every new question you may have.
Thank you for understanding.