只需将此代码添加到函数中。php
add_filter( \'wp_dropdown_cats\', \'wp_dropdown_cats_multiple\', 10, 2 );
function wp_dropdown_cats_multiple( $output, $r ) {
if( isset( $r[\'multiple\'] ) && $r[\'multiple\'] ) {
$output = preg_replace( \'/^<select/i\', \'<select multiple\', $output );
$output = str_replace( "name=\'{$r[\'name\']}\'", "name=\'{$r[\'name\']}[]\'", $output );
foreach ( array_map( \'trim\', explode( ",", $r[\'selected\'] ) ) as $value )
$output = str_replace( "value=\\"{$value}\\"", "value=\\"{$value}\\" selected", $output );
}
return $output;
}
并添加多个参数,如下所示:
<div class="ci-select">
<?php
wp_dropdown_categories( array(
\'taxonomy\' => \'property_location\',
\'hierarchical\' => true,
\'show_option_none\' => esc_html_x( \'-\', \'any property location\', \'ci_theme\' ),
\'option_none_value\' => \'\',
\'name\' => \'s_property_location\',
\'id\' => \'property_location\',
\'selected\' => isset( $_GET[\'s_property_location\'] ) ? $_GET[\'s_property_location\'] : \'\', // e.x 86,110,786
\'multiple\' => true
) );
?>
</div>