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
— theselect
name as in<select name="<here>">
, and you should set it totheme
which is your custom taxonomy slug. -
value_field
— the value of the<option>
‘s in thatselect
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 tohttps://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 customtheme
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 toget_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' ),
);