Yes. All you need to do is to add a taxonomy parameter to the search form, depending on which page you are.
Put something like this in your search form:
<?php if (you're on a tagged page) : ?>
<input type="hidden" name="Location" value="<?php // get the taxonomy value and echo it here ?> />
<?php endif; ?>
Something like that, just fill in the details. That used to work just like that, but using taxonomies directly as query parameters was deprecated in 3.1 in favour of tax_query structure. So, this may or may not work directly, but if it doesn’t, you need to add another filter that reads in the Location query parameter and constructs a tax_query out of it (see WP_Query in Codex).
That’s what I’ve been trying. I got it to work manually, but can’t get it to echo out the taxonomy in the value=””
I managed to get to this point.
<?php
$taxonomy = 'location';
$terms = wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
if( $terms ) {
echo $term->term_id;
}
?>
The problem I have now is that it outputs the first id in the list and not the last. So it echos the id for United States not Millbrae
Terms hierarchy –
United States
California
Peninsula
Millbrae
The other problem I have is if I try add that to the value in the search input I get location=%0D%0A%09&s=pizza instead of location=11742&s=pizza
%0D%0A%09 is a space, a return and a linefeed.
You echo $term->term_id – where is that $term defined? Above that the variable is called $terms.