It is really simple. set_theme_mod
File: /wp-includes/theme.php
889: function set_theme_mod( $name, $value ) {
890: $mods = get_theme_mods();
891: $old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;
892:
893: /**
894: * Filters the theme mod value on save.
895: *
896: * The dynamic portion of the hook name, `$name`, refers to the key name of
897: * the modification array. For example, 'header_textcolor', 'header_image',
898: * and so on depending on the theme options.
899: *
900: * @since 3.9.0
901: *
902: * @param string $value The new value of the theme mod.
903: * @param string $old_value The current value of the theme mod.
904: */
905: $mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value );
906:
907: $theme = get_option( 'stylesheet' );
908: update_option( "theme_mods_$theme", $mods );
909: }
will save into the options table theme_mods_$theme
where $theme
is your theme name. But this will not happen until you press the Save & Publish Customizer button.
The preview page is like a dream land (Lat: Et est fallacia lunae).
Whatever you do the values will not be saved to the database.
And I think this is the only issue you are facing.
I duped what you have on your end.
I can confirm I can save the values every time.
function _20161230_customize_register( $wp_customize ) {
$active_type="home";
$wp_customize->add_section( $active_type. 'just_listed' , array(
'title' => __( 'Just Listed Settings', 'microformata' ),
'priority' => 53,
) );
$wp_customize->add_setting($active_type.'_categories_max',array(
'default' => '10',
'transport' => 'refresh'
));
$wp_customize->add_control( $active_type.'_categories_max',array(
'type' => 'select',
'label' => 'Max Items',
'section' => $active_type.'just_listed',
'choices' => array(
'5' => '2',
'10' => '10',
'15' => '15',
'20' => '20',
),
));
}
add_action( 'customize_register', '_20161230_customize_register' );
The Ajax result will be like this:
{success: true, data: {setting_validities: {home_categories_max: true}, changeset_status: "publish",…}}
data
:
{setting_validities: {home_categories_max: true}, changeset_status: "publish",…}
changeset_status
:
"publish"
next_changeset_uuid
:
"4b1ac702-3ae2-422d-875a-a02b6f5b2d65"
setting_validities
:
{home_categories_max: true}
success
:
true
What I am not sure, can you disable plugins you use and then test.
I know you use 4.7, because of the error message you got.