There’s subtle things in UX that we seem to take for granted this applies to developers as well as users, here’s something so simple but makes a big difference in terms of a users experience. Have you ever gotten frustrated when you’ve used a Select Dropdown menu to search for something but once it’s submitted and the screen has refreshed it doesn’t save what you last searched for? Well here’s the answer to that very problem.
Using the below code snippet you’ll be able to generate a Select Dropdown from any number of Taxonomy Terms, the whole thing is dynamic too which means it can be used across multiple taxonomies, obviously your Search template and Search Form need to reflect this but hopefully it should be useful regardless.
It will ensure that whatever value (in this case Taxonomy Term) is passed to the Select Dropdown will be saved on refresh making the whole UX experience a bit more polished and informed.
<?php $taxonomy = 'YOUR TAXONOMY HERE'; $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true ); $tax_terms = get_terms( $taxonomy, $args ); ?> <!--Select Field START --> <select name="<? echo $taxonomy ?>" id="<? echo $taxonomy ?>" class="postform"> <option value="" selected="selected">Choose YOUR TAXONOMY NAME HERE</option> <?php if($tax_terms): ?> <?php foreach ($tax_terms as $tax_term): ?> <option value="<?php echo $tax_term->slug; ?>" <?php if ( isset( $_GET[ $taxonomy ] ) && ( $_GET[ $taxonomy ] == $tax_term->slug ) ) echo "selected";?>><?php echo $tax_term->name; ?></option> <?php endforeach; ?> <?php endif; ?> </select> <!-- Select Field End -->