Ask your WordPress questions! Pay money and get answers fast! (more info)

Exclude Taxonomy ID from search WordPress

  • REFUNDED

My current code is below.

I have been able to exclude taxonomy id - 201 from the dropdown list. However, if you search all property types it still shows in the results.

I also want to exclude this item (201) when some one searches all property types.





<?php
//property types drop down
if (isset($_GET['property_types'])) { $category_ID = $_GET['property_types']; } else { $category_ID = 0; }
if ($category_ID > 0) {
//Do nothing
} else {
$category_ID = 0;
}
$dropdown_options = array (

'show_option_all' => __(get_option('woo_label_property_type_dropdown_view_all')),




'hide_empty' => 0,
'hierarchical' => 1,
'show_count' => 0,

'orderby' => 'name',
'name' => 'property_types',
'id' => 'property_types',
'taxonomy' => 'propertytype',

'exclude' => '201',
'hide_if_empty' => 1,




Thanks

Paul

Answers (3)

2011-04-27

derekshirk answers:

If you are interested in using a plugin - this is my favorite:
http://wordpress.org/extend/plugins/search-everything/

I will allow you to easily exclude any category, page or post ID from search results along with a whole bunch of other great options - I highly recommend it. I have attached a sample screen shot to show you what the admin UI looks like.

There is also another plugin that I know of but have never used. You can check it out here:
http://gudlyf.com/2005/03/08/wordpress-plugin-category-visibility/

-----

If you are looking for a non plugin solution try this:

The IDs are set in the array. The filter is only working if it is the search is_search and if you are not ! in the backend is_admin.


// search filter
function fb_search_filter($query) {
if ( !$query->is_admin && $query->is_search) {
$query->set('post__not_in', array(40, 9) ); // id of page or post
}
return $query;
}
add_filter( 'pre_get_posts', 'fb_search_filter' );


If you like to exclude the subpage of a page, then you can add it to the ID.


// search filter
function fb_search_filter($query) {
if ( !$query->is_admin && $query->is_search) {
$pages = array(2, 40, 9); // id of page or post
// find children to id
foreach( $pages as $page ) {
$childrens = get_pages( array('child_of' => $page, 'echo' => 0) );
}
// add id to array
for($i = 0; $i < sizeof($childrens); ++$i) {
$pages[] = $childrens[$i]->ID;
}
$query->set('post__not_in', $pages );
}
return $query;
}
add_filter( 'pre_get_posts', 'fb_search_filter' );


There are many possibilities and I hope I was able to give you a starting point if you like to exclude posts and pages in your search.

----

Not 100% sure about that but it should. If not, try this....

Did you manually create the custom post type yourself or did you use a plugin to create it. If you manually created the new Custom Post Type, try this:


// Here we create our custom post type for a feeds
add_action('init', 'my_custom_init');

// This is where we set our variables
function my_custom_init() {
$labels = array(
'name' => _x('Feeds', 'post type general name'),
'singular_name' => _x('Feed', 'post type singular name'),
'add_new' => _x('Add Feed', 'Feed Item'),
'add_new_item' => __('Add New Feed'),
'edit_item' => __('Edit Feed'),
'edit' => _x('Edit', 'feed'),
'new_item' => __('New Feed'),
'view_item' => __('View Feed Information'),
'search_items' => __('Search Feeds'),
'not_found' => __('No feeds were found with that criteria'),
'not_found_in_trash' => __('No feed found in Trash'),
'view' => __('View Feed')
);

// Additional arguments (where we place our search exclusion)
$args = array(
'labels' => $labels,
// This is where we set whether the new post type gets included in a search or not
// Defaults to false, but you'll want to set it to true to exclude the item
'exclude_from_search' => true,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'custom-fields', 'revisions', 'page-attributes')
);

register_post_type('feeds',$args);
}




----

If you feel that my answer helped you solve your problem please vote my answer as the winner!


boz85 comments:

Sorry I forgot to mention it is a custom property search - website url - http://www.onlyrent.co.uk/# and not the standard WP search.

So the plugin will be no good.

Will this code still work for a taxonomy of a custom post type?

Custom Post Type - Property
Taxonomy - Property Type

Thanks

Paul


boz85 comments:

Hi David,

Yes.

I have two custom search pages (property-search-commercial.php and property search.php).

Both search pages send results to property-search-results.php.

When I add a new property, it has a taxonomy called property type.

If you use the two search forms:

http://www.oemah.com/
http://www.oemah.com/commercial-search/

The default setting on both forms for property type is (show_options_all). However, i want to exclude the residential listings from the commercial and vice versa.

I have been able to exclude the results on the results.php however this also excludes them on the other search form.

It's been driving me crazy : (

2011-04-27

Peter Michael answers:

Use [[LINK href="http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts"]]pre_get_posts[[/LINK]]


boz85 comments:

Not sure where to put this code? Or if it will do what i want.


I have two search pages, both using the same taxonomies (Property Type).

One search is for commercial types, the other for residential.

On the residential search, i want to exclude all the commercial property types (Id's 201, 202, 203).

However, if you search with 'select all' selected, it still displays the taxonomies (property types). I need to exclude them just in this search.

2011-04-27

David Navarrete answers:

global $query_string;

$taxonomy = 'nameoftaxonomy';



$terms = array();

$_terms = get_terms( $taxonomy, array( 'fields' => 'names' ) );

if ( is_array( $_terms ) ) {

$terms = $_terms;

}

$myquery = wp_parse_args( $query_string );

$myquery['tax_query'] = array(

array(

'taxonomy' => 'tumblog',

'terms' => $terms,

'field' => 'slug',

'operator' => 'NOT IN'

)

);



query_posts( $myquery );


boz85 comments:

Hi,

Where do I place this code in relation to my existing code above?

Still could not get it to work : (

Thanks

Paul


David Navarrete comments:

on the template of search. You have wordpress 3.1?


boz85 comments:

Im using a custom search.

Code is below:
<?php if (defined('DSIDXPRESS_OPTION_NAME')) { $options = get_option(DSIDXPRESS_OPTION_NAME); } else { $options = array('Activated' => false); } ?>
<div class="search-tab <?php if(get_option('woo_idx_plugin_search') != 'true'){ echo 'no-idx'; }?>">
<?php if(get_option('woo_search_header')) { ?>
<span id="local-search" class="current"><?php echo stripslashes(get_option('woo_search_header')); ?></span>
<?php if ( $options['Activated'] && ( get_option('woo_idx_plugin_search') == 'true' ) ) { ?>
<span id="mls-search"><a class="red-highlight"><?php echo stripslashes(get_option('woo_search_mls_header')); ?></a></span>
<?php } ?>
<?php } ?>
</div>

<div id="search_for_rent">

<div class="for_rent_title"><h2><?php _e('Search for rentals', 'woothemes'); ?></H2></div>
<div class="for_rent_desc"><?php _e('View residential, commercial and student property listings on Only Rent', 'woothemes'); ?></div>


<form name="property-webref-search" id="property-webref-search" method="get" action="<?php bloginfo('url'); ?>/">

<input type="text" class="text webref" id="s-webref" name="s" value="<?php _e('Property ID', 'woothemes'); ?>" onfocus="if (this.value == '<?php _e('Property ID', 'woothemes'); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('Property ID', 'woothemes'); ?>';}" />

<input type="submit" class="submit button" name="property-search-webref-submit" value="<?php _e('Go To', 'woothemes'); ?>" />

</form>

<form name="property-search" id="property-search_for_rent" method="get" action="<?php bloginfo('url'); ?>/">

<div class="query">

<?php
if (isset($_GET['s'])) { $keyword = strip_tags($_GET['s']); } else { $keyword = ''; }
if ( $keyword == 'View More' ) { $keyword = ''; }
?>

<input type="text" class="main-query text" id="s-main" name="s" value="<?php if ( $keyword != '' ) { echo $keyword; } else { _e(get_option('woo_search_keyword_text'), 'woothemes'); } ?>" onfocus="if (this.value == '<?php _e(get_option('woo_search_keyword_text'), 'woothemes') ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e(get_option('woo_search_keyword_text'), 'woothemes') ?>';}" />

<input type="submit" class="submit button" name="property-search-submit" value="<?php _e('Search', 'woothemes'); ?>" />





<div class="fix"></div>

<div class="for_rent_eg">e.g. 'York', 'NW3', 'NW3 5TY' or 'Waterloo station'</div>

</div><!-- /.query -->

<div class="filters">

<?php if (isset($_GET['sale_type'])) { $sale_type = $_GET['sale_type']; } else { $sale_type = ''; }
if ($sale_type == '') { $sale_type = 'rent'; } ?>

<div class="saletype">
<label for="saletype"><?php _e(get_option('woo_label_sale_type'), 'woothemes'); ?>:</label>

<input type="radio" name="sale_type" value="rent" <?php if ($sale_type == 'rent') { ?>checked<?php } ?>> <?php _e(get_option('woo_label_for_rent'), 'woothemes') ?>

</div><!-- /.saletype -->

<div class="location-type">

<label><?php _e(get_option('woo_label_property_location_and_type'), 'woothemes'); ?>:</label>

<?php
//property locations drop down
if (isset($_GET['location_names'])) { $category_ID = $_GET['location_names']; } else { $category_ID = 0; }
if ($category_ID > 0) {
//Do nothing
} else {
$category_ID = 0;
}


$dropdown_options = array (
'show_option_all' => __(get_option('woo_label_locations_dropdown_view_all')),

'show_option_all' => 'name',
'hide_empty' => 0,
'hierarchical' => 1,
'depth' => 1,
'show_count' => 0,
'orderby' => 'name',
'name' => 'location_names',
'id' => 'location_names',
'taxonomy' => 'location',

'exclude' => '',
'hide_if_empty' => 1,
'selected' => $category_ID
);
wp_dropdown_categories($dropdown_options);
?>



<?php
//property types drop down
if (isset($_GET['property_types'])) { $category_ID = $_GET['property_types']; } else { $category_ID = 0; }
if ($category_ID > 0) {
//Do nothing
} else {
$category_ID = 0;
}


$dropdown_options = array (

'show_option_all' => __(get_option('woo_label_property_type_dropdown_view_all')),




'hide_empty' => 0,
'hierarchical' => 1,
'show_count' => 0,

'orderby' => 'name',
'name' => 'property_types',
'id' => 'property_types',
'taxonomy' => 'propertytype',

'exclude' => '201',
'hide_if_empty' => 1,
'selected' => $category_ID,
'class' => 'last'
);

global $query_string;



$taxonomy = 'House';


$terms = array();


$_terms = get_terms( $taxonomy, array( 'fields' => 'names' ) );


if ( is_array( $_terms ) ) {



$terms = $_terms;


}


$myquery = wp_parse_args( $query_string );


$myquery['tax_query'] = array(


array(


'taxonomy' => 'propertytype',


'terms' => $terms,


'field' => 'slug',


'operator' => 'NOT IN'


)



);







query_posts( $myquery );





wp_dropdown_categories($dropdown_options);

if (isset($_GET['price_min'])) { $price_min = $_GET['price_min']; } else { $price_min = ''; }
if (isset($_GET['price_max'])) { $price_max = $_GET['price_max']; } else { $price_max = ''; }


?>


<?php if (isset($_GET['no_beds'])) { $no_beds = $_GET['no_beds']; } else { $no_beds = 'all'; } ?>

<?php $options_features_amount = array("0","1","2","3","4","5","6","7","8","9","10+"); ?>




<label for="no_beds"><?php _e(get_option('woo_label_beds'), 'woothemes'); ?>:</label>
<select class="postform" id="no_beds" name="no_beds">
<option <?php if ($no_beds == 'all') { ?>selected="selected"<?php }?> value="all"><?php _e('Any', 'woothemes') ?></option>
<?php
foreach ($options_features_amount as $option) {
?><option <?php if ($no_beds == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php
}
?>

</div><!-- /.location-type -->




<div class="price">
<label for="price_min"><?php _e(get_option('woo_label_min_price'), 'woothemes'); ?> <?php echo '('.get_option('woo_estate_currency').')'; ?>:</label><input type="text" class="text price validate_number" name="price_min" id="price_min" value="<?php if ( $price_min != '' ) { echo $price_min; } ?>" >
<label for="price_max"><?php _e(get_option('woo_label_max_price'), 'woothemes'); ?> <?php echo '('.get_option('woo_estate_currency').')'; ?>:</label><input type="text" class="text price validate_number" name="price_max" id="price_max" value="<?php if ( $price_max != '' ) { echo $price_max; } ?>" >
</div><!-- /.price -->




</div><!-- /.filters -->



<?php
$term_names = '';
$price_list = '';
$size_list = '';
//Taxonomies
$taxonomy_data_set = get_terms(array('location'), array('fields' => 'names'));
$taxonomy_data_set = woo_multidimensional_array_unique($taxonomy_data_set);
foreach ($taxonomy_data_set as $data_item) {
//Convert string to UTF-8
$str_converted = woo_encoding_convert($data_item);
//Add category name to data string
$term_names .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').',';
}

$price_list = '';
//Post Custom Fields
$meta_data_fields = array('price');
$meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields);
$meta_data_set = woo_multidimensional_array_unique($meta_data_set);
foreach ($meta_data_set as $data_item) {
//Convert string to UTF-8
$str_converted = woo_encoding_convert($data_item->meta_value);
//Add category name to data string
$price_list .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').',';
}
//Post Custom Fields
$meta_data_fields = array('size');
$meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields);
$meta_data_set = woo_multidimensional_array_unique($meta_data_set);
foreach ($meta_data_set as $data_item) {
//Convert string to UTF-8
$str_converted = woo_encoding_convert($data_item->meta_value);
//Add category name to data string
$size_list .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').',';
}
?>

<script>
jQuery(document).ready(function($) {

<?php if ( ( ($no_garages == 'all') || ($no_garages == '') ) && ( ($no_beds == 'all') || ($no_beds == '') ) && ( ($no_baths == 'all') || ($no_baths == '') ) && ( $size_min == '' ) && ( $size_max == '' ) ) { ?>jQuery("#advanced-search").toggle();<?php } ?>

jQuery(".advanced-search-button").click(function(){
var hidetext = 'Hide <?php echo get_option('woo_label_advanced_search'); ?>';
var showtext = '<?php echo get_option('woo_label_advanced_search'); ?>';
var currenttext = jQuery(".advanced-search-button").text();
//toggle advanced search
jQuery("#advanced-search").toggle();
//toggle text
if (currenttext == hidetext) {
jQuery(".advanced-search-button").text(showtext);
//reset search values
jQuery("#no_garages").val('all');
jQuery("#no_beds").val('all');
jQuery("#no_baths").val('all');
}
else {
jQuery(".advanced-search-button").text(hidetext);
}
});
//GET PHP data items
var keyworddataset = "<?php echo $term_names; ?>".split(",");
var pricedataset = "<?php echo $price_list; ?>".split(",");
var sizedataset = "<?php echo $size_list; ?>".split(",");
//Set autocomplete(s)
$("#s-main").autocomplete(keyworddataset);
$("#price_min").autocomplete(pricedataset);
$("#price_max").autocomplete(pricedataset);
$("#size_min").autocomplete(sizedataset);
$("#size_max").autocomplete(sizedataset);
//Handle autocomplete result
$("#s").result(function(event, data, formatted) {
//Do Nothing
});
$("#price_min").result(function(event, data, formatted) {
//Do Nothing
});
$("#price_max").result(function(event, data, formatted) {
//Do Nothing
});
$("#size_min").result(function(event, data, formatted) {
//Do Nothing
});
$("#size_max").result(function(event, data, formatted) {
//Do Nothing
});

});
</script>



</form>

<?php

if ( $options['Activated'] && ( get_option('woo_idx_plugin_search') == 'true' ) ) {

$pluginUrl = DSIDXPRESS_PLUGIN_URL;

$formAction = get_bloginfo("url");
if (substr($formAction, strlen($formAction), 1) != "/")
$formAction .= "/";
$formAction .= dsSearchAgent_Rewrite::GetUrlSlug();

?>

<form name="property-mls-search" id="property-mls-search" method="get" action="<?php echo $formAction; ?>">

<?php

$defaultSearchPanels = dsSearchAgent_ApiRequest::FetchData("AccountSearchPanelsDefault", array(), false, 60 * 60 * 24);
$defaultSearchPanels = $defaultSearchPanels["response"]["code"] == "200" ? json_decode($defaultSearchPanels["body"]) : null;

$propertyTypes = dsSearchAgent_ApiRequest::FetchData("AccountSearchSetupPropertyTypes", array(), false, 60 * 60 * 24);
$propertyTypes = $propertyTypes["response"]["code"] == "200" ? json_decode($propertyTypes["body"]) : null;

$requestUri = dsSearchAgent_ApiRequest::$ApiEndPoint . "LocationsByType";
//cities
$location_cities = explode("\n", get_option('woo_idx_search_cities'));
//communities
$location_communities = explode("\n", get_option('woo_idx_search_communities'));
//Tracts
$location_tracts = explode("\n", get_option('woo_idx_search_tracts'));
//Zips
$location_zips = explode("\n", get_option('woo_idx_search_zips'));
?>

<div class="mls-property-type">

<label for="idx-q-PropertyTypes"><?php _e('Property Type', 'woothemes'); ?>:</label>
<select name="idx-q-PropertyTypes" class="dsidx-search-widget-propertyTypes">
<option value="All">- All property types -</option>
<?php
if (is_array($propertyTypes)) {
foreach ($propertyTypes as $propertyType) {
$name = htmlentities($propertyType->DisplayName);
echo "<option value=\"{$propertyType->SearchSetupPropertyTypeID}\">{$name}</option>";
}
}
?>
</select>

<label for="idx-q-MlsNumbers"><?php _e('MLS #', 'woothemes'); ?>:</label>
<input id="idx-q-MlsNumbers" name="idx-q-MlsNumbers" type="text" class="text" />

</div>



<div class="mls-area-details">

<label for="idx-q-Cities"><?php _e('City', 'woothemes'); ?>:</label>
<select id="idx-q-Cities" name="idx-q-Cities" class="small">
<option value="">- Any -</option>
<?php if (is_array($location_cities)) {
foreach ($location_cities as $city) {
$city_name = htmlentities(trim($city));
echo "<option value=\"{$city_name}\">$city_name</option>";
}
} ?>
</select>

<label for="idx-q-Communities"><?php _e('Community', 'woothemes'); ?>:</label>
<select id="idx-q-Communities" name="idx-q-Communities" class="small">
<option value="">- Any -</option>
<?php if (is_array($location_communities)) {
foreach ($location_communities as $community) {
$community_name = htmlentities(trim($community));
echo "<option value=\"{$community_name}\">$community_name</option>";
}
} ?>
</select>

<label for="idx-q-TractIdentifiers"><?php _e('Tract', 'woothemes'); ?>:</label>
<select id="idx-q-TractIdentifiers" name="idx-q-TractIdentifiers" class="small">
<option value="">- Any -</option>
<?php if (is_array($location_tracts)) {
foreach ($location_tracts as $tract) {
$tract_name = htmlentities(trim($tract));
echo "<option value=\"{$tract_name}\">$tract_name</option>";
}
} ?>
</select>

<label for="idx-q-ZipCodes"><?php _e('Zip', 'woothemes'); ?>:</label>
<select id="idx-q-ZipCodes" name="idx-q-ZipCodes" class="small">
<option value="">- Any -</option>
<?php if (is_array($location_zips)) {
foreach ($location_zips as $zip) {
$zip_name = htmlentities(trim($zip));
echo "<option value=\"{$zip_name}\">$zip_name</option>";
}
} ?>
</select>

</div>



<div class="mls-features">

<label for="idx-q-PriceMin"><?php _e('Min Price', 'woothemes'); ?>:</label>
<input id="idx-q-PriceMin" name="idx-q-PriceMin" type="text" class="text validate_number" />

<label for="idx-q-PriceMax"><?php _e('Max Price', 'woothemes'); ?>:</label>
<input id="idx-q-PriceMax" name="idx-q-PriceMax" type="text" class="text validate_number" />

<label for="idx-q-ImprovedSqFtMin"><?php _e('Min Size', 'woothemes'); ?> <?php echo '(SQ FT)'; ?>:</label>
<input id="idx-q-ImprovedSqFtMin" name="idx-q-ImprovedSqFtMin" type="text" class="text validate_number" />

<label for="idx-q-BedsMin"><?php _e('Beds', 'woothemes'); ?>:</label>
<input id="idx-q-BedsMin" name="idx-q-BedsMin" type="text" class="text validate_number" />

<label for="idx-q-BathsMin"><?php _e('Baths', 'woothemes'); ?>:</label>
<input id="idx-q-BathsMin" name="idx-q-BathsMin" type="text" class="text validate_number" />

</div>

<input type="submit" value="Search" class="submit button" />

<?php
if($options["HasSearchAgentPro"] == "yes"){

echo 'try our&nbsp;<a href="'.$formAction.'advanced/"><img src="'.$pluginUrl.'assets/adv_search-16.png" /> Advanced Search</a>';
}
?>


</form>
<?php } ?>
</div><!-- /#search_for_sale -->


David Navarrete comments:


try with this


<?php if (defined('DSIDXPRESS_OPTION_NAME')) { $options = get_option(DSIDXPRESS_OPTION_NAME); } else { $options = array('Activated' => false); } ?>

<div class="search-tab <?php if(get_option('woo_idx_plugin_search') != 'true'){ echo 'no-idx'; }?>">

<?php if(get_option('woo_search_header')) { ?>

<span id="local-search" class="current"><?php echo stripslashes(get_option('woo_search_header')); ?></span>

<?php if ( $options['Activated'] && ( get_option('woo_idx_plugin_search') == 'true' ) ) { ?>

<span id="mls-search"><a class="red-highlight"><?php echo stripslashes(get_option('woo_search_mls_header')); ?></a></span>

<?php } ?>

<?php } ?>

</div>



<div id="search_for_rent">



<div class="for_rent_title"><h2><?php _e('Search for rentals', 'woothemes'); ?></H2></div>

<div class="for_rent_desc"><?php _e('View residential, commercial and student property listings on Only Rent', 'woothemes'); ?></div>





<form name="property-webref-search" id="property-webref-search" method="get" action="<?php bloginfo('url'); ?>/">



<input type="text" class="text webref" id="s-webref" name="s" value="<?php _e('Property ID', 'woothemes'); ?>" onfocus="if (this.value == '<?php _e('Property ID', 'woothemes'); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('Property ID', 'woothemes'); ?>';}" />



<input type="submit" class="submit button" name="property-search-webref-submit" value="<?php _e('Go To', 'woothemes'); ?>" />



</form>



<form name="property-search" id="property-search_for_rent" method="get" action="<?php bloginfo('url'); ?>/">



<div class="query">



<?php

if (isset($_GET['s'])) { $keyword = strip_tags($_GET['s']); } else { $keyword = ''; }

if ( $keyword == 'View More' ) { $keyword = ''; }

?>



<input type="text" class="main-query text" id="s-main" name="s" value="<?php if ( $keyword != '' ) { echo $keyword; } else { _e(get_option('woo_search_keyword_text'), 'woothemes'); } ?>" onfocus="if (this.value == '<?php _e(get_option('woo_search_keyword_text'), 'woothemes') ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e(get_option('woo_search_keyword_text'), 'woothemes') ?>';}" />



<input type="submit" class="submit button" name="property-search-submit" value="<?php _e('Search', 'woothemes'); ?>" />











<div class="fix"></div>



<div class="for_rent_eg">e.g. 'York', 'NW3', 'NW3 5TY' or 'Waterloo station'</div>



</div><!-- /.query -->



<div class="filters">



<?php if (isset($_GET['sale_type'])) { $sale_type = $_GET['sale_type']; } else { $sale_type = ''; }

if ($sale_type == '') { $sale_type = 'rent'; } ?>



<div class="saletype">

<label for="saletype"><?php _e(get_option('woo_label_sale_type'), 'woothemes'); ?>:</label>



<input type="radio" name="sale_type" value="rent" <?php if ($sale_type == 'rent') { ?>checked<?php } ?>> <?php _e(get_option('woo_label_for_rent'), 'woothemes') ?>



</div><!-- /.saletype -->



<div class="location-type">



<label><?php _e(get_option('woo_label_property_location_and_type'), 'woothemes'); ?>:</label>



<?php

//property locations drop down

if (isset($_GET['location_names'])) { $category_ID = $_GET['location_names']; } else { $category_ID = 0; }

if ($category_ID > 0) {

//Do nothing

} else {

$category_ID = 0;

}





$dropdown_options = array (

'show_option_all' => __(get_option('woo_label_locations_dropdown_view_all')),



'show_option_all' => 'name',

'hide_empty' => 0,

'hierarchical' => 1,

'depth' => 1,

'show_count' => 0,

'orderby' => 'name',

'name' => 'location_names',

'id' => 'location_names',

'taxonomy' => 'location',



'exclude' => 201,

'hide_if_empty' => 1,

'selected' => $category_ID

);

wp_dropdown_categories($dropdown_options);

?>







<?php

//property types drop down

if (isset($_GET['property_types'])) { $category_ID = $_GET['property_types']; } else { $category_ID = 0; }

if ($category_ID > 0) {

//Do nothing

} else {

$category_ID = 0;

}





$dropdown_options = array (



'show_option_all' => __(get_option('woo_label_property_type_dropdown_view_all')),









'hide_empty' => 0,

'hierarchical' => 1,

'show_count' => 0,



'orderby' => 'name',

'name' => 'property_types',

'id' => 'property_types',

'taxonomy' => 'propertytype',



'exclude' => '201',

'hide_if_empty' => 1,

'selected' => $category_ID,

'class' => 'last'

);



global $query_string;







$taxonomy = 'House';





$terms = array();





$_terms = get_terms( $taxonomy, array( 'fields' => 'names' ) );





if ( is_array( $_terms ) ) {







$terms = $_terms;





}





$myquery = wp_parse_args( $query_string );





$myquery['tax_query'] = array(





array(





'taxonomy' => 'propertytype',





'terms' => $terms,





'field' => 'slug',





'operator' => 'NOT IN'





)







);















query_posts( $myquery );











wp_dropdown_categories($dropdown_options);



if (isset($_GET['price_min'])) { $price_min = $_GET['price_min']; } else { $price_min = ''; }

if (isset($_GET['price_max'])) { $price_max = $_GET['price_max']; } else { $price_max = ''; }





?>





<?php if (isset($_GET['no_beds'])) { $no_beds = $_GET['no_beds']; } else { $no_beds = 'all'; } ?>



<?php $options_features_amount = array("0","1","2","3","4","5","6","7","8","9","10+"); ?>









<label for="no_beds"><?php _e(get_option('woo_label_beds'), 'woothemes'); ?>:</label>

<select class="postform" id="no_beds" name="no_beds">

<option <?php if ($no_beds == 'all') { ?>selected="selected"<?php }?> value="all"><?php _e('Any', 'woothemes') ?></option>

<?php

foreach ($options_features_amount as $option) {

?><option <?php if ($no_beds == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php

}

?>



</div><!-- /.location-type -->









<div class="price">

<label for="price_min"><?php _e(get_option('woo_label_min_price'), 'woothemes'); ?> <?php echo '('.get_option('woo_estate_currency').')'; ?>:</label><input type="text" class="text price validate_number" name="price_min" id="price_min" value="<?php if ( $price_min != '' ) { echo $price_min; } ?>" >

<label for="price_max"><?php _e(get_option('woo_label_max_price'), 'woothemes'); ?> <?php echo '('.get_option('woo_estate_currency').')'; ?>:</label><input type="text" class="text price validate_number" name="price_max" id="price_max" value="<?php if ( $price_max != '' ) { echo $price_max; } ?>" >

</div><!-- /.price -->









</div><!-- /.filters -->







<?php

$term_names = '';

$price_list = '';

$size_list = '';

//Taxonomies

$taxonomy_data_set = get_terms(array('location'), array('fields' => 'names'));

$taxonomy_data_set = woo_multidimensional_array_unique($taxonomy_data_set);

foreach ($taxonomy_data_set as $data_item) {

//Convert string to UTF-8

$str_converted = woo_encoding_convert($data_item);

//Add category name to data string

$term_names .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').',';

}



$price_list = '';

//Post Custom Fields

$meta_data_fields = array('price');

$meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields);

$meta_data_set = woo_multidimensional_array_unique($meta_data_set);

foreach ($meta_data_set as $data_item) {

//Convert string to UTF-8

$str_converted = woo_encoding_convert($data_item->meta_value);

//Add category name to data string

$price_list .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').',';

}

//Post Custom Fields

$meta_data_fields = array('size');

$meta_data_set = woo_get_custom_post_meta_entries($meta_data_fields);

$meta_data_set = woo_multidimensional_array_unique($meta_data_set);

foreach ($meta_data_set as $data_item) {

//Convert string to UTF-8

$str_converted = woo_encoding_convert($data_item->meta_value);

//Add category name to data string

$size_list .= htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8').',';

}

?>



<script>

jQuery(document).ready(function($) {



<?php if ( ( ($no_garages == 'all') || ($no_garages == '') ) && ( ($no_beds == 'all') || ($no_beds == '') ) && ( ($no_baths == 'all') || ($no_baths == '') ) && ( $size_min == '' ) && ( $size_max == '' ) ) { ?>jQuery("#advanced-search").toggle();<?php } ?>



jQuery(".advanced-search-button").click(function(){

var hidetext = 'Hide <?php echo get_option('woo_label_advanced_search'); ?>';

var showtext = '<?php echo get_option('woo_label_advanced_search'); ?>';

var currenttext = jQuery(".advanced-search-button").text();

//toggle advanced search

jQuery("#advanced-search").toggle();

//toggle text

if (currenttext == hidetext) {

jQuery(".advanced-search-button").text(showtext);

//reset search values

jQuery("#no_garages").val('all');

jQuery("#no_beds").val('all');

jQuery("#no_baths").val('all');

}

else {

jQuery(".advanced-search-button").text(hidetext);

}

});

//GET PHP data items

var keyworddataset = "<?php echo $term_names; ?>".split(",");

var pricedataset = "<?php echo $price_list; ?>".split(",");

var sizedataset = "<?php echo $size_list; ?>".split(",");

//Set autocomplete(s)

$("#s-main").autocomplete(keyworddataset);

$("#price_min").autocomplete(pricedataset);

$("#price_max").autocomplete(pricedataset);

$("#size_min").autocomplete(sizedataset);

$("#size_max").autocomplete(sizedataset);

//Handle autocomplete result

$("#s").result(function(event, data, formatted) {

//Do Nothing

});

$("#price_min").result(function(event, data, formatted) {

//Do Nothing

});

$("#price_max").result(function(event, data, formatted) {

//Do Nothing

});

$("#size_min").result(function(event, data, formatted) {

//Do Nothing

});

$("#size_max").result(function(event, data, formatted) {

//Do Nothing

});



});

</script>







</form>



<?php



if ( $options['Activated'] && ( get_option('woo_idx_plugin_search') == 'true' ) ) {



$pluginUrl = DSIDXPRESS_PLUGIN_URL;



$formAction = get_bloginfo("url");

if (substr($formAction, strlen($formAction), 1) != "/")

$formAction .= "/";

$formAction .= dsSearchAgent_Rewrite::GetUrlSlug();



?>



<form name="property-mls-search" id="property-mls-search" method="get" action="<?php echo $formAction; ?>">



<?php



$defaultSearchPanels = dsSearchAgent_ApiRequest::FetchData("AccountSearchPanelsDefault", array(), false, 60 * 60 * 24);

$defaultSearchPanels = $defaultSearchPanels["response"]["code"] == "200" ? json_decode($defaultSearchPanels["body"]) : null;



$propertyTypes = dsSearchAgent_ApiRequest::FetchData("AccountSearchSetupPropertyTypes", array(), false, 60 * 60 * 24);

$propertyTypes = $propertyTypes["response"]["code"] == "200" ? json_decode($propertyTypes["body"]) : null;



$requestUri = dsSearchAgent_ApiRequest::$ApiEndPoint . "LocationsByType";

//cities

$location_cities = explode("\n", get_option('woo_idx_search_cities'));

//communities

$location_communities = explode("\n", get_option('woo_idx_search_communities'));

//Tracts

$location_tracts = explode("\n", get_option('woo_idx_search_tracts'));

//Zips

$location_zips = explode("\n", get_option('woo_idx_search_zips'));

?>



<div class="mls-property-type">



<label for="idx-q-PropertyTypes"><?php _e('Property Type', 'woothemes'); ?>:</label>

<select name="idx-q-PropertyTypes" class="dsidx-search-widget-propertyTypes">

<option value="All">- All property types -</option>

<?php

if (is_array($propertyTypes)) {

foreach ($propertyTypes as $propertyType) {

$name = htmlentities($propertyType->DisplayName);

echo "<option value=\"{$propertyType->SearchSetupPropertyTypeID}\">{$name}</option>";

}

}

?>

</select>



<label for="idx-q-MlsNumbers"><?php _e('MLS #', 'woothemes'); ?>:</label>

<input id="idx-q-MlsNumbers" name="idx-q-MlsNumbers" type="text" class="text" />



</div>







<div class="mls-area-details">



<label for="idx-q-Cities"><?php _e('City', 'woothemes'); ?>:</label>

<select id="idx-q-Cities" name="idx-q-Cities" class="small">

<option value="">- Any -</option>

<?php if (is_array($location_cities)) {

foreach ($location_cities as $city) {

$city_name = htmlentities(trim($city));

echo "<option value=\"{$city_name}\">$city_name</option>";

}

} ?>

</select>



<label for="idx-q-Communities"><?php _e('Community', 'woothemes'); ?>:</label>

<select id="idx-q-Communities" name="idx-q-Communities" class="small">

<option value="">- Any -</option>

<?php if (is_array($location_communities)) {

foreach ($location_communities as $community) {

$community_name = htmlentities(trim($community));

echo "<option value=\"{$community_name}\">$community_name</option>";

}

} ?>

</select>



<label for="idx-q-TractIdentifiers"><?php _e('Tract', 'woothemes'); ?>:</label>

<select id="idx-q-TractIdentifiers" name="idx-q-TractIdentifiers" class="small">

<option value="">- Any -</option>

<?php if (is_array($location_tracts)) {

foreach ($location_tracts as $tract) {

$tract_name = htmlentities(trim($tract));

echo "<option value=\"{$tract_name}\">$tract_name</option>";

}

} ?>

</select>



<label for="idx-q-ZipCodes"><?php _e('Zip', 'woothemes'); ?>:</label>

<select id="idx-q-ZipCodes" name="idx-q-ZipCodes" class="small">

<option value="">- Any -</option>

<?php if (is_array($location_zips)) {

foreach ($location_zips as $zip) {

$zip_name = htmlentities(trim($zip));

echo "<option value=\"{$zip_name}\">$zip_name</option>";

}

} ?>

</select>



</div>







<div class="mls-features">



<label for="idx-q-PriceMin"><?php _e('Min Price', 'woothemes'); ?>:</label>

<input id="idx-q-PriceMin" name="idx-q-PriceMin" type="text" class="text validate_number" />



<label for="idx-q-PriceMax"><?php _e('Max Price', 'woothemes'); ?>:</label>

<input id="idx-q-PriceMax" name="idx-q-PriceMax" type="text" class="text validate_number" />



<label for="idx-q-ImprovedSqFtMin"><?php _e('Min Size', 'woothemes'); ?> <?php echo '(SQ FT)'; ?>:</label>

<input id="idx-q-ImprovedSqFtMin" name="idx-q-ImprovedSqFtMin" type="text" class="text validate_number" />



<label for="idx-q-BedsMin"><?php _e('Beds', 'woothemes'); ?>:</label>

<input id="idx-q-BedsMin" name="idx-q-BedsMin" type="text" class="text validate_number" />



<label for="idx-q-BathsMin"><?php _e('Baths', 'woothemes'); ?>:</label>

<input id="idx-q-BathsMin" name="idx-q-BathsMin" type="text" class="text validate_number" />



</div>



<input type="submit" value="Search" class="submit button" />



<?php

if($options["HasSearchAgentPro"] == "yes"){



echo 'try our&nbsp;<a href="'.$formAction.'advanced/"><img src="'.$pluginUrl.'assets/adv_search-16.png" /> Advanced Search</a>';

}

?>





</form>

<?php } ?>

</div><!-- /#search_for_sale -->


boz85 comments:

Hi David,

No luck, still does not exclude the taxonomies from the search results.

I have been able to exclude them by adding code to the search results page, but this is no good for me as I have two search forms linked to the results page.

If i exclude taxonomies from the results.php it will affect the other search form : (

I need to exclude the taxonomies in the search.php

Is this possible?


David Navarrete comments:

give me the code of search.php is the same above? let me try with other response


boz85 comments:

My main property-search.php

http://pastebin.com/5XXz6PFg

Many thanks

Paul


David Navarrete comments:

you can give access to the wp?, i need look for something


send me pm


David Navarrete comments:

check now, i need the name of term 201 , the taxonomy is location?


boz85 comments:

Sorry I have the theme installed on two websites.

For Oemah.com

Try Taxonomy - Commercial (ID 62)

Many Thanks


David Navarrete comments:

now exclude the term 62, try now, or give me acceso to the other site..


boz85 comments:

Still does not work : (


David Navarrete comments:

the idea is exclude all properies with type comercial?


boz85 comments:

Hi David,

Yes.

I have two custom search pages (property-search-commercial.php and property search.php).

Both search pages send results to property-search-results.php.

When I add a new property, it has a taxonomy called property type.

If you use the two search forms:

http://www.oemah.com/
http://www.oemah.com/commercial-search/

The default setting on both forms for property type is (show_options_all). However, i want to exclude the residential listings from the commercial and vice versa.

I have been able to exclude the results on the results.php however this also excludes them on the other search form.

It's been driving me crazy : (


David Navarrete comments:

i edit the search.php now, edit property-search-results.php
Select theme to edit:


TRY NOW


boz85 comments:

Hi there,

Unfortunately this is no good, as i said earlier I have multiple search forms going to search results page.

By excluding the taxonomy 'commercial' from the search results page, it also removes from the other search forms linked to the results page.

I was hoping I could filter this in the search form (show_options_all), however after speaking to a knowledgeable web designer it looks like this is not possible and i will have to create seperate search results pages for each search form.

Thanks