How to Set Customizer Values by Javascript in a Multidimensional Array

Sometimes you may need to set the values in a multidimensional array in the customizer settings. For a single value like text field, text area or radio button it is pretty easy but for a multidimensional array, it is a complex one.

Use the below code to save in a multidimensional array.

var banner_buttons_arr = JSON.parse( decodeURIComponent( wp.customize('banner_buttons').get() ) );
banner_buttons_arr[0]['btn_bg_color'] = '#000';
banner_buttons.set(banner_buttons_arr);
wp.customize('banner_buttons').get() // banner_buttons field is a multidimensional array

Written By

CodeDevil

Leave a Reply

Your email address will not be published. Required fields are marked *