How advanced search forms are displayed
The advanced search forms are displayed via advanced_search.php. Here we load different templates accordingly to the what type of search you selected.
if ($adv_search_type==1){
include(locate_template('templates/advanced_search_type1.php'));
}else if ($adv_search_type==3){
include(locate_template('templates/advanced_search_type3.php'));
}else if ($adv_search_type==4){
include(locate_template('templates/advanced_search_type4.php'));
}else if ($adv_search_type==5){
include(locate_template('templates/advanced_search_type5.php'));
}else if ($adv_search_type==6){
include(locate_template('templates/advanced_search_type6.php'));
}else if ($adv_search_type==7){
include(locate_template('templates/advanced_search_type7.php'));
} else if ($adv_search_type==8){
include(locate_template('templates/advanced_search_type8.php'));
} else if ($adv_search_type==9){
include(locate_template('templates/advanced_search_type9.php'));
}else if ($adv_search_type==10){
include(locate_template('templates/advanced_search_type10.php'));
}else if ($adv_search_type==11){
include(locate_template('templates/advanced_search_type11.php'));
}else{
f( !is_tax() && basename ( get_page_template() ) !== 'advanced_search_results.php'){
include(locate_template('templates/advanced_search_type2.php'));
}else{
include(locate_template('templates/advanced_search_type1.php'));
}
Let’s look over advanced_search_type1.php file
Here are 2 situations – when you have default search fields or when you have custom fields.
When you have the default fields the search fields are loaded via function wpestate_show_search_field_classic_form
$search_form = wpestate_show_search_field_classic_form('main',$action_select_list,$categ_select_list ,$select_city_list,$select_area_list);
The wpestate_show_search_field_classic_form is located in functions.php. Please note that in the beginning of the file we set different classes or id’s . These are set based on the $position parameter (main – is the main form, sidebar, shortcode, mobile)
if ($postion=='main'){
$caret_class = ' caret_filter ';
$main_class = ' filter_menu_trigger ';
$appendix = '';
$price_low = 'price_low';
$price_max = 'price_max';
$ammount = 'amount';
$slider = 'slider_price';
$drop_class = '';
After that we fill up the $return_string with the default fields – considering the classes and id’s we set in the beginning of the function.
If the search has custom fields then the we use another function inside a foreach that loops trough custom fields.
foreach($adv_search_what as $key=>$search_field){
wpestate_show_search_field('mainform',$search_field,$action_select_list,$categ_select_list,$select_city_list,$select_area_list,$key,$select_county_state_list);
}
The function wpestate_show_search_field() is in help_functions,
Here we are doing the same thing – set some classes and id’s considering the $position parameter – where we will use the function
after that we create the search form considering the custom fields you selected
if you pick type – see code in if block
else if($search_field=='types'){
if you pick categories- see code in if block
}else if($search_field=='categories'){
if you pick cities- see code in if block
} else if($search_field=='cities'){
if you pick areas- see code in if block
} else if($search_field=='areas'){
if you pick county / state – see code in if block
}else if($search_field=='county / state'){
if is none of the above see the else branch
}else {
$show_dropdowns = get_option(‘wp_estate_show_dropdowns’,”);
$string = wpestate_limit45 ( sanitize_title ($adv_search_label[$key]) );
$slug = sanitize_key($string);
In the last branch we check if the custom field is a dropdown or not, if is property price ( and display the input forms or slider – see wpestate_price_form_adv_search() ) , if we have a datepicker etc.
Beside the main forms described above there are 3 additional search forms
- Widget – located in widgets/advanced_search.php
- Shortcode – located in shortcodes.php, function wpestate_advanced_search_function ()
- Mobile – located in adv_search_mobile.php
All the above search fields use the same functions like the ones described in advanced_search_type1.php
Advanced Search type 2 – with autocomplete
In this case all the forms elements are located in advanced_search_type2.php file.
The most important thing is the autocompletion suggestion list . This is made via jquery ui autcomplete functions at line 84. The suggestion list is $availableTags and is composed from cities, areas and counties that are already inserted into database.
$availableTags='';
$args = array( 'hide_empty=0' );
$terms = get_terms( 'property_city', $args );
foreach ( $terms as $term ) {
$availableTags.= '"'.$term->name.'",';
}
$terms = get_terms( ‘property_area’, $args );
foreach ( $terms as $term ) {
$availableTags.= ‘”‘.$term->name.'”,’;
}
$terms = get_terms( ‘property_county_state’, $args );
foreach ( $terms as $term ) {
$availableTags.= ‘”‘.$term->name.'”,’;
}
See also Technical how to: Advanced Search explained – advanced search results page