I want to filter my custom post type Job
by taxonomies. I have two taxonomies, department
and location
. I post my working code for only my first taxonomy. How can I modify it so that it will work for the second taxonomy too?
<?php
$term = isset($_GET['department']) ? sanitize_text_field($_GET['department']) : false;
$selected = '';
$tax_query = '';
if ($term) {
$term = get_term_by('slug', $term, 'department');
if (!empty($term->name)) {
$selected = $term->name;
$tax_query = array(
array(
'taxonomy' => 'department',
'terms' => $term,
)
);
}
}
?>
<form id="tool-category-select" class="tool-category-select" action="<?php the_permalink(); ?>" method="get">
<?php
wp_dropdown_categories(
array(
'orderby' => 'NAME',
'taxonomy' => 'department',
'name' => 'department',
'value_field' => 'slug',
'show_option_all' => 'Departments',
'selected' => $selected,
)
);
?>
<input type="submit" name="submit" value="view"/>
</form>