title: Passing Selected Value in WordPress Category Dropdown
body: <p>I have a custom taxonomy and I've added a category dropdown to the archive page to allow users to quickly switch between categories. I have the following code, which works in redirecting users to the new category that they choose. However, the dropdown always defaults to the first option in the <code>&lt;select&gt;</code>. How can I pass the selected <code>&lt;option&gt;</code> through and set it as the default value when a user switches categories?</p>
  
  <pre><code>&lt;?php
  $args = array(
    'taxonomy'     =&gt; 'custom_taxonomy',
    'orderby'      =&gt; 'name',
    'show_count'   =&gt; 1,
    'hierarchical' =&gt; 1,
    'title_li'     =&gt; 'title'
  );
  
  &lt;form id="categoriesform" action="&lt;?php bloginfo('url'); ?&gt;" method="post"&gt;
      &lt;div&gt;
          &lt;?php $cats = get_categories($args); ?&gt;
          &lt;select id="categories" name="custom_taxonomy"&gt;
              &lt;option value="allCategories"&gt;All Categories&lt;/option&gt;
              &lt;?php foreach ($cats as $cat) : ?&gt;
                  &lt;option value="&lt;?php echo get_term_link($cat, $cat-&gt;taxonomy) ?&gt;"&gt;
                  &lt;?php echo $cat-&gt;name ?&gt;&lt;/option&gt;
              &lt;?php endforeach; ?&gt;
          &lt;/select&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;script&gt;
  jQuery(document).ready(function() {
      jQuery('#categories').change(function() {
          if (jQuery(this).val() == 'allCategories') {
              window.location = 'http://example.com/all-categories';
          } else {
              window.location = jQuery(this).val();
          }
      });
  });
  &lt;/script&gt;
  </code></pre>