wp_dropdown_categories()
函数有一个参数show_option_all
如果选中,则在所有术语中搜索。我的自定义帖子类型选择中需要类似的内容:
<form method="GET" action="<?php echo esc_url( home_url() ); ?>">
<div class="select-wrap">
<label>Select location</label>
<?php
$args = array(
\'show_option_all\' => \'All locations\',
\'hierarchical\' => 1,
\'hide_empty\' => 0,
\'orderby\' => \'name\',
\'echo\' => 1,
\'value_field\' => \'slug\',
);
$args[\'taxonomy\'] = \'location\';
$args[\'class\'] = \'select--field\';
wp_dropdown_categories( $args );
?>
</div>
<div class="select-wrap">
<label>Select service</label>
<select class="select--field">
<?php
$args = array(
\'post_type\' => \'service\',
\'posts_per_page\' => -1
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
echo \'<option value="\' . get_the_ID() . \'">\' . get_the_title() . \'</option>\';
endwhile;
wp_reset_postdata();
?>
</select>
</div>
<input type="hidden" name="taxonomy" value="location">
<input type="hidden" name="post_type" value="service">
<button type="submit" class="search-btn btn--lg">Submit</button>
</form>