Do I need to run
new WP_Query()
and rebuild the HTML table?
No, you absolutely do not need to! And actually, you don’t even need to hook on parse_query
(which BTW, is an action and not a filter).
All you need to do is set your categories dropdown’s name
to the taxonomy name/slug, which you’ve already done so, and set the value_field
argument to slug
, and then WordPress will automatically filter the posts based on the selected banner_cat
term.
So just remove the entire add_filter('parse_query', ...)
part from your code, and set the value_field
like so:
wp_dropdown_categories([
'show_option_all' => get_taxonomy($tax)->label,
'taxonomy' => $tax,
'name' => $tax, // use the taxonomy name/slug
'orderby' => 'name',
'order' => 'DESC',
'selected' => $selected,
'hide_empty' => false,
'hierarchical' => true,
'value_field' => 'slug', // set to 'slug'
]);