0

I have a customizer option that simply creates a dropdown populated with pages from the site. I need this dropdown to have the ability for multiple selections? Any ideas?

$wp_customize->add_control('options_my_dropdown',
array(
    'label' => __('My Label'),
    'description' => esc_html__('My Description'),
    'section' => 'options_section',
    'type' => 'dropdown-pages'
)
);

1 Answer 1

0

Yes, this is possible, but you will have to really, really want it. It's difficult, because WordPress does not natively support the multiple argument on select inputs in the customizer. You can see this in de the render_content function which outputs the html (just search the function for <select). And even if you would succeed to add the argument, the customizer wouldn't know what to do with the selected items.

So, to get this done, you will have to extend the customizer. In terms of lines of code this is doable. WordPress itself contains multiple extensions to the customizer controls, for instance to add a color picker as an input type. Here's roughly what to do:

  1. Create a new file WP_Customize_Control_Multiselect
  2. Check out the basic content in the color picker. You will need a line public $type = 'multiselect';, a simple constructor like the one in the color picker and a rendering function which you can adapt from the dropdown-pages part of WP_Customize_Control.
  3. Don't forget to include the file in your functions.php and call the control with $wp_customize->add_control (new Customize_Control_Multiselect ...
4
  • That might be tough, I'll have to look into it more I guess. I just need the user to be able to enter multiple URLs. I thought this way would be simplest but I might just end up using a comma separated list in a textarea :(
    – Jon
    Commented May 16 at 15:58
  • Depending on how many pages there are you could also opt for a list of checkboxes
    – cjbj
    Commented May 17 at 12:20
  • Actually, I could probably make checkboxes work. Any idea how to get that working?
    – Jon
    Commented May 17 at 13:16
  • wordpress.stackexchange.com/questions/68052/…
    – cjbj
    Commented May 17 at 13:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.