I am trying to find a way to send a value between 2 setting fields inside of the WordPress customizer.
My further goal is to create a preset button. I click a button inside of the customizer, and it applies pre-created values to all the other fields.
To make it easier, here is a basic example:
I have two option fields inside of the customizer. When I change the value of field 1
, I would like field 2
to automatically updates to that same value as well.
theme-customizer.js
// Field 1
wp.customize( 'field1', function( value ) {
value.bind( function( newval ) {
//no need to make any css changes with this field.
} );
} );
// Field 2
wp.customize( 'field2', function( value ) {
value.bind( function( newval ) {
$('.site-container').css('border-style', newval +'px' );
} );
} );
Is there away that I could update the value of field2
when field1
is clicked?
For example:
// Field 1
wp.customize( 'field1', function( value ) {
value.bind( function( newval ) {
wp.customize.value( 'field2 )(newval);//Setting the new value.
} );
} );
This does work on the live preview, but the new value of field2
is not being saved when I click save. It seems the value is not being put through to PHP when using:
wp.customize.value( 'field2 )(newval);