2

i have a function of custom taxonomies to display a drop down list on my website, which is working fine, but there is one problem, the default value is a custom taxonomy, but that i dont want, i want a custom word, like select cause the current default value, when i select it, it is not redirecting to the corresponding page, if you wanna chaeck it, goto my website, on the home page i have kept that drop-down list www.mbas.in

and the code of the function is

function the_taxonomy_dropdown($taxonomy) {
      $id = "{$taxonomy}-dropdown";
      $js =<<<SCRIPT
    <script type="text/javascript">
     jQuery(document).ready(function($){
      $("select#{$id}").change(function(){
        window.location.href = $(this).val();
      });
     });
    </script>
    SCRIPT;
      echo $js;
      $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');
    }

what i do for keeping default value as Select ????

3
  • 1
    Do not redirect your visitor onChange. Without a mouse it will be very hard to get to the third item.
    – fuxia
    Dec 10, 2010 at 16:03
  • what if i want to use another drop down with diff taxonomy so that if user select anything from that drop down it redirects to the corresponding template.
    – user48408
    Mar 3, 2014 at 6:03
  • @Rahul that would be a new question
    – Tom J Nowell
    Mar 3, 2014 at 6:09

1 Answer 1

2

Not sure exactly what you're asking. Do you just want to include a blank value before the list of terms? Would this work:

echo '<option value="#"> - Select - </option>';

(inserted just before the line foreach($terms as $term) {)

1
  • hey thanks it worked, it was so easy i didnt figured it out, thanks for your help Dec 10, 2010 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.