The advanced search results page is made by publishing a page with the the template “Advanced Search Results” template. The file for this template is advanced_search_results.php
*** IMPORTANT: we only use WordPress wp_query ( and an array of arguments that is usually named $args) when doing the actual search. Wordpress has an extended article about wp_query here : https://codex.wordpress.org/Class_Reference/WP_Query .If you plan do changes on search script read their documentation first.
The search algorithm is different for advanced search type 2 compared with advanced search type 1 and also if you are using custom fields instead of default fields.
at line 51 we check if the search type is different than type 2
if( !isset($_GET['is2']) ){
after that we check if is custom advanced search
if( $custom_advanced_search==='yes' ){
If we use custom fields we are asking for the search arguments using function wpestate_search_results_custom () . If you have default fields then the search arguments array will be returned by the function wpestate_search_results_default()
When you have the default fields and advanced search type 1 or 3
The wpestate_search_results_default is located in libs/searchfunctions.php at like 335
Categories parameters like city ,category or area are set by buulding the 4 arrays ($categ_array, $action_array, $city_array and $area_array) that are inside the ‘tax_query’
'tax_query' => array(
'relation' => 'AND',
$categ_array,
$action_array,
$city_array,
$area_array,
Price, bathrooms or bathrooms are search using ‘meta_query’ parameter .
When you have custom fields and advanced search type 1 or 3
The wp_query arguments array is created via function wpestate_search_results_custom located in searchfunctions.php at line 3
Here we get the custom fields info using
$adv_search_what = get_option('wp_estate_adv_search_what','');
$adv_search_how = get_option('wp_estate_adv_search_how','');
$adv_search_label = get_option('wp_estate_adv_search_label','');
$adv_search_type = get_option('wp_estate_adv_search_type','');
and then we loop trough the custom fields and build the arguments array,
Same as in the case of default fields we use
Categories parameters like city ,category or area are set by buulding the 4 arrays ($categ_array, $action_array, $city_array , $area_array, $countystate_array) that are inside the ‘tax_query’
'tax_query' => array(
'relation' => 'AND',
$categ_array,
$action_array,
$city_array,
$area_array,
$countystate_array
Price, bathrooms or bathrooms are search using ‘meta_query’ parameter .
Please note that there are also 2 filters in advanced_search_results.php
add_filter( 'posts_orderby', 'wpestate_my_order' ); // at line 96 - is ordering the listing by the featured property and the id parameter - The featured listings will appear first (set in $arg array) and they will be orderd by id (set by filter)
add_filter( 'posts_where', 'wpestate_title_filter', 10, 2 ); // used when you have keyword search
When you have advanced search type 2 (custom fields are not applicable for type 2)
In this case the arguments array is build using wpestated_advanced_search_tip2() located in searchfunctions.php at line 678.
Categories parameters like city ,category or area are set by buulding the 4 arrays ($categ_array, $action_array and $location_array) that are inside the ‘tax_query’
'tax_query' => array(
'relation' => 'AND',
$categ_array,
$action_array,
$location_array
After the arument array is built (the $args variable) we check to see if theadvacend search results page is a classic one or a half map one
if ( $property_list_type_status == 2 ){
get_template_part('templates/half_map_core');
$half_map_results=1;
}else{
get_template_part('templates/normal_map_core');
}
The actual wp_query is made in the file above using the $args you set here. The display of the results is also made in those files.
See also Technical how to: Advanced Search explained – advanced search forms