When I run a test with:
- Text search 'adhd' and set IFS Training Level to IFS Level 3 gives the correct result.
I see only the following post as result: Eleanor Carn
When I checked the post in backend the address field has the following value: "B30 2SU GB"
when I checked the address is not full address "B30 2SU GB". Can you please first setup correct full address. For testing purpose - I tried to check with "Lewis Road, Stirchley, Birmingham B30 2SU, UK" but not luck.
I see you setup text search with option "Title, body and custom fields" using relevanssi:
- https://toolset.com/documentation/user-guides/views/searching-texts-custom-fields-views-relevanssi/#integration-with-custom-searches
If you check the above Doc - it clearly says - just above "Known issues" heading:
Once you add a search filter that includes custom fields, the entire search operation is performed by the Relevanssi plugin, which means that Relevanssi is also responsible for providing the results order. This is why the Views sorting order options are not used. This includes ordering results by distance in a search for posts that include a Toolset Maps address field, where Relevanssi determines the ordering.
Here is the related ticket:
- https://toolset.com/forums/topic/combined-search-field-and-distance-filter-in-view/
However - I'm trying to provide you the best solution I can that might help you and if that does not suits your needs then you will have to make a decision to not combine both text search and distance search.
To offer you the solution, I've created the following view that will return the result without text search but distance and all other filters:
- hidden link
Where - added all the query filters to filter by URL param and just excluded the text search for this view:
Distance
Show posts within 40mi radius of address/coordinates provided using toolset_maps_distance_center URL parameter.
Taxonomy filter
Select posts with taxonomy:
Sessions slug in one of those set by the URL parameter wpv-session
eg. hidden link
AND
Availability slug in one of those set by the URL parameter wpv-availability
eg. hidden link
AND
IFS Training Levels slug in one of those set by the URL parameter wpv-ifs-training-level
eg. hidden link
AND
IFS Qualifications slug in one of those set by the URL parameter wpv-ifs-qualification
eg. hidden link
Custom field filter
Select items with field:
Languages spoken is a string like URL_PARAM(wpv-wpcf-languages-spoken)
And configured the Loop Editor as given under - that will return the post IDs:
[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=other][wpv-post-id],[wpv-item index=last][wpv-post-id]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found]0[/wpv-no-items-found][wpv-layout-end]
Then to the "Custom Code" section I've adjusted the code as given under:
function func_update_distance_radius_from_urlparam( $view_settings, $view_id ) {
$allowed_views = array(2096,2478);
if (in_array($view_id,$allowed_views)) {
if(isset($_REQUEST['toolset_maps_distance_radius']) and
$_REQUEST['toolset_maps_distance_radius']!='') {
$view_settings['map_distance_filter']['map_distance']= $_REQUEST['toolset_maps_distance_radius'];
}
}
return $view_settings;
}
add_filter( 'wpv_view_settings', 'func_update_distance_radius_from_urlparam', 5, 2 );
add_filter( 'wpv_view_settings', 'func_set_orderby_distance', 101, 2 );
function func_set_orderby_distance( $view_settings, $view_id ){
if ( $view_id == 1432 ) {
$address_field_slug = 'address';
if(isset($_GET['toolset_maps_distance_center']) and $_GET['toolset_maps_distance_center'] != '' ) {
$view_settings['orderby'] = "field-wpcf-$address_field_slug";
$view_settings['orderby_as'] = 'DISTANCE';
$view_settings['order'] = 'ASC';
$view_settings['distance_order'] = array(
'source' => 'url_parameter',
'center' => '',
'url_parameter' => 'toolset_maps_distance_center'
);
}
}
return $view_settings;
}
add_filter( 'wpv_filter_query', 'func_text_search_with_distance', 101, 3 );
function func_text_search_with_distance($query_args,$view_settings, $view_id ){
if ( $view_id == 1432 ) {
if( isset($_GET['wpv_post_search']) and !empty($_GET['wpv_post_search']) and
isset($_GET['toolset_maps_distance_center']) and !empty($_GET['toolset_maps_distance_center'])
){
$tax_query = $query_args['tax_query'];
$meta_query = $query_args['meta_query'];
$search_keyword = $_GET['wpv_post_search'];
//// searching results with relevanssi
$args = array(
's' => $search_keyword,
'numberposts' => -1,
'fields'=> 'ids',
'post_types' => array( 'practitioner' ),
'relevanssi' => true,
'tax_query' => $tax_query,
'meta_query' => $meta_query
);
$text_search_result = new WP_Query( $args );
$text_search = array();
if(!empty($text_search_result->posts)){
$text_search = $text_search_result->posts;
}
//// getting distance search results
$geo_result = array();
$result = do_shortcode('[wpv-view name="get-all-distance-filter-results" cached="off"]');
$geo_result = explode(",",trim($result));
$final_result = array_intersect($text_search, $geo_result);
$query_args['post__in'] = $final_result ;
}
}
return $query_args;
}
Can you confirm it works as expected now.