How can I set and get the values of a multiple select with the Wordpress settings API for a theme options page? -


i want use 'multiple select field' field in theme option page using settings api.

i tried below code unable save selected values, saves last 1 selected.

add_action('admin_menu', 'create_theme_options_page');  function create_theme_options_page() {   add_options_page('theme options', 'theme options', 'administrator', 'inc/site-options.php', 'build_options_page'); }  add_action('admin_init', 'register_and_build_fields');  function register_and_build_fields() {    register_setting('plugin_options', 'plugin_options', 'validate_setting'); add_settings_field('clusters', 'choose clusters show:', 'cluster_setting', __file__, 'site_section'); }   function cluster_setting() {   $options = get_option('plugin_options');  echo "<select name='plugin_options[clusters]' multiple='multiple'> <option value='location'>location</option> <option value='role'>role</option> <option value='functional'>functional area</option> <option value='industry'>industry</option> </select>" } 

how can select multiple values select element , save them.

any appreciated.

try using

<select name='plugin_options[clusters][]' multiple='multiple'>

instead. ensure clusters value saved array instead of string


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -