I have a dropdown with Regular select. I need a dropdown with Multiselect. I added the JavaScript script file inside header.php
, now I need add string multiple="multiple"
.
In firebug I multiple = "multiple"
in a string
Now I need add string multiple="multiple"
in to this block but I don’t know how do this:
<?php
$terms = wp_get_post_terms( $post->ID,"listing_category" );
$terms = isset($terms[0]) ? $terms[0]->term_id : "";
if(get_field("custom_attributes_input_types","options") == "Dropdowns"):
wp_dropdown_categories(
array(
'taxonomy' => 'listing_category',
'hiera`enter code here`rchical'=>1,
'show_option_none'=>__('Choose Category:','um_lang'),
'name' => 'listing_category',
'hide_empty' => false,
'selected' => $terms
)
);
else:
?>
Take a look at the source of
wp_dropdown_categories()
. It useswalk_category_dropdown_tree()
to render the output. Right after that you have a filter namedwp_dropdown_cats
that allows altering the final MarkUp:You could now use a Regex and
preg_replace
or parse it usingDOMDocument
, etc.Keep in mind that you should change the
select
elementsName
attribute as well – else you wouldn’t be able to save an array. Example:Still you’ll need to change the
walker
argument and rewrite the Walker itself. The reason can be read inWalker_CategoryDropdown::start_el
:As you can see currently it’s checking only a single value, not an array. So basically you’ll need a check against your array. Example overriding method that checks against an array:
Put above method in a new class that extends
Walker_CategoryDropdown
and put that new Walker class as argument into your args array forwp_dropdown_categories()
:As you can see, I added the option
foo
, which comes from thename="foo[]"
above. The specific implementation is up to you. This answer shall just serve as guide towards your solution.