Wp Customize active change Controls count

Here my section

I want to dynamicly change controls count in my section.

This is my section.

That block which tell how many blocks user choice

$wp_customize -> add_setting('medcomp-frontpage-services-pages-count', array(
        'default' => '4'));

$wp_customize -> add_control ( new WP_Customize_Control($wp_customize, 'medcomp-frontpage-services-pages-count-control', array(
            'label' => __('Services count', 'medcomp'),
            'section' => 'medcomp-frontpage-services',
            'settings' => 'medcomp-frontpage-services-pages-count',
            'type' => 'select',
            'choices'=>array(
                '1' => '1',
                '2' => '2',
                '3'=>'3',
                '4' => '4',
                '5' => '5',
                '6' => '6',
                '7' => '7',
                '8' => '8',
                '9' => '9',),
        )) );

And this is my Controls

function register_number_dropdown_medcomp($wp_customize){
            $num_sections = get_theme_mod('medcomp-frontpage-services-pages-count');

    for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {

        $wp_customize->add_setting( 'panel_' . $i, array(
            'default'           => false,) );

        $wp_customize->add_control( 'panel_' . $i, array(
            /* translators: %d is the front page section number */
            'label'          => sprintf( __( 'Service %d ', 'medcomp' ), $i ),
            'description'    => ( 1 !== $i ? '' : __( 'Here You can Choose pages', 'medcomp' ) ),
            'section'        => 'medcomp-frontpage-services',
            'type'           => 'dropdown-pages',
            'allow_addition' => true,

        ) );

    }
}
add_action ('customize_register', 'register_number_dropdown_medcomp');

How can I dynamicaly change $num_sections with Javascript or php ?

Read more here:: Wp Customize active change Controls count

Leave a Reply

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