#StackBounty: #taxonomy #theme-customizer WordPress Customizer – pass setting value into another control to live update drop-down choices

Bounty: 100

In the WordPress customizer script, I am trying to pass the value from a select control into a custom control that displays taxonomies associated with the selected value (1st control).

$wp_customize->add_control( new Tax_Dropdown_Control( $wp_customize, 'select_tax', array(
    'section'       => 'section_1',
    'label'         => __( 'Select Post Taxonomy', 'textdomain' ),
    'description'   => __( 'Select a taxonomy based on post type selected.', 'textdomain' ),
    'dropdown_args' => array(
        'post_type' => $wp_customize->get_setting("select_post_type"), // here I need to pass the first setting's value
    ),
) ) );

// custom controls related snippet
class Tax_Dropdown_Control extends WP_Customize_Control {
    .....    
    $dropdown_args = wp_parse_args( $this->dropdown_args, array(
        'post_type' => 'post',
    ) );
        
    $dropdown_args['echo'] = false;
                
    $taxonomies = get_object_taxonomies($dropdown_args);
                
    if  ($taxonomies) {
        echo '<select>';
        foreach ($taxonomies  as $taxonomy ) {
            echo '<option>'. $taxonomy. '</option>';
        }
        echo '</select>';
    } 
    ....
}

It would need to update the choices live when the select post type is changed. I’m not sure if maybe an active_callback can be used to recall the function with the updated variable?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.