I have created custom post type called "case study"(with slug case-study), with support of custom taxonomy which is called "theme".

What i am trying to achieve? Simple dropdown, with redirect to specific taxonomy term page on option select.

The code:

action="<?php bloginfo('url'); ?>" method="get">


    $args = array(
        'show_option_all'  => __( 'Choose theme', 'l-p' ),
        'hide_empty'       => 0,
        'echo'             => 0,
        'show_count'       => 0,
        'taxonomy'         => 'theme',

    $select  = wp_dropdown_categories( $args );
    $replace = "<select$1 onchange='return this.form.submit()'>";
    $select  = preg_replace( '#<select([^>]*)>#', $replace, $select );

    echo $select;


    <noscript><input type="submit" value="View" /></noscript>


Thing is, i'm getting dropdown with proper list of taxonomy terms, but when clicking on specifc option(from dropdown) it redirects me to weird pages/urls instead of actual taxonomy template page.

  • I have tried saving direct links in wp settings.
  • Taxonomy have proper template called taxonomy-theme.php
  • The same dropdown works properly for default blog posts.
  • CPT and taxonomy is created via CPT UI(i'm not really fond of it, but well, it was "required") - the support for taxonomy/cpt is checked in options.
  • The slug for custom taxonomy is "theme".
  • The slug for custom post type is "case-study".
  • The taxonomy terms pages are present, it's just that dropdown redirects incorrectly.

Any help would be much appreciated.

2 Answers 2


You can get your code to work the expected way by adding the following three arguments to your $args array which you pass to wp_dropdown_categories():

  • name — the select name as in <select name="<here>">, and you should set it to theme which is your custom taxonomy slug.

  • value_field — the value of the <option>'s in that select dropdown, e.g. <option value="<here>">.

    And you should set the arg to slug so that when the form is submitted (or when a term is selected), the browser would go to https://example.com/?theme=term-slug-here and then WordPress redirects the browser to the correct term permalink if (and it's commonly) enabled.

  • selected — the selected option which is a term in the custom theme taxonomy and because the form's destination is the term archive page, and that a term slug was specified (see the sample URL above), then set this arg to get_query_var( 'theme' ) to get the slug of the term being queried on the page.

So try with:

$args = array(
    'show_option_all' => __( 'Choose theme', 'l-p' ),
    'hide_empty'      => 0,
    'echo'            => 0,
    'show_count'      => 0,
    'taxonomy'        => 'theme',

    // Add these three args:
    'name'            => 'theme', // same as the "taxonomy" above
    'value_field'     => 'slug',  // use the term slug
    'selected'        => get_query_var( 'theme' ),

Custom post type category dropdown with custom taxonomy slug:

      $obj = get_queried_object();
      $cat_slug = $obj->slug;
        'taxonomy' => 'custom-post-category',
        'hide_empty' => 1,
        'hierarchical' => true,
        'orderby' => 'name',
        'show_option_none' => 'All',
        'value_field' => 'slug',
        'selected' => $cat_slug  ) );
<script type="text/javascript">
$(document).ready( function(){
$("#cat").change(function () {
    var selected = $("#cat option:selected");
    if(selected.val() != -1) {
      var destination = "<?php echo get_option('home');?>/custom-post-category/"; 
      if(selected.attr("class") == "level-1"){
         destination += selected.prevAll("option.level-0:first").val()+"/";
      destination += selected.val()+"/";
    } else {
      var destination = "<?php echo get_option('home');?>/custom-post/";
    location.href = destination;

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.