Last active
December 3, 2017 15:36
-
-
Save parsakafi/000e1fe4c42cd18526096dc34b9e1731 to your computer and use it in GitHub Desktop.
wp_dropdown_categories multi select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_dropdown_categories_pk($name, $taxonomy, $selected = array()) | |
{ | |
$select = wp_dropdown_categories(array( | |
'name' => $name, | |
'show_option_none' => '- Category -', | |
'option_none_value' => '-1', | |
'taxonomy' => $taxonomy, | |
'hierarchical' => 1, | |
'echo' => false | |
)); | |
if (is_array($selected)) | |
foreach ($selected as $sel) | |
if (!empty($sel) && $sel != '-1') | |
$select = str_replace('value="' . $sel . '"', 'value="' . $sel . '" selected', $select); | |
return $select; | |
} | |
// Active Multi Select | |
function dropdown_filter($output, $r) | |
{ | |
$output = preg_replace('/<select (.*?) >/', '<select $1 size="5" multiple>', $output); | |
return $output; | |
} | |
add_filter('wp_dropdown_cats', 'dropdown_filter', 10, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Categories: | |
<?php echo wp_dropdown_categories_pk('multiple_categories[]', 'category', array(10,12)); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment