WP Customizer. How to set a value using javascript.
-
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 2 option fields inside of WP customizer.
When I change the value of field 1, I would like that field 2, automatically updates to that 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 usingwp.customize.value( 'field2 )(newval);
- The topic ‘WP Customizer. How to set a value using javascript.’ is closed to new replies.