drop-down list another query
-
16-10-2019 - |
Question
i tried this code, it is not giving me any 404 page instead it is giving me the same page back, now i think the submit buttons needs to be configured
function the_taxonomy_dropdown($taxonomy) {
$id = "{$taxonomy}-dropdown";
$terms = get_terms($taxonomy);
echo "<select name=\"{$id}\" id=\"{$id}\">";
foreach($terms as $term) {
echo '<option value="';
echo get_term_link(intval($term->term_id),$taxonomy);
echo '">' . "{$term->name}</option>";
}
echo "</select>";
}
add_action('init','jquery_init');
function jquery_init() {
wp_enqueue_script('jquery');
}
this code was provided to me by one of the person from this website, i just modified it, this works but its just showing me the home page again
Solution
Just a standard HTML form will do!
<form action="<?php echo home_url('/'); ?>" method="get">
<p><?php wp_dropdown_categories('taxonomy=taxonomy-1&name=taxonomy-1'); ?></p>
<p><?php wp_dropdown_categories('taxonomy=taxonomy-2&name=taxonomy-2'); ?></p>
<p><input type="submit" value="Search!" /></p>
</form>
Just replace taxonomy-1
and taxonomy-2
with the names of your taxonomies.
Important
If you registered your taxonomy with a custom query_var
, you'll need to match it in the name
argument of wp_dropdown_categories()
.
Also, querying multiple taxonomies is not supported as of 3.02 - you'll need the 3.1 beta, a plugin or additional filters.
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange