Search code examples
wordpresscheckboxredux-framework

How to show fields below checkbox based on "checked" in Redux Framework?


I've downloaded the Redux Framework (using generator). I want some fields to be displayed if a checkbox field is checked (more related fields below checkbox).

I searched online and found some Redux code having checkbox_hide_below field which is not present in the current Redux Framework.

Will I have to do it all by myself or Redux framework provides some option to show/hide fields?


Solution

  • Lead dev of Redux here.

    You'd have to do it yourself, however it's really pretty easy.

    First, you'd do a get_option to your opt_name before you run your config. Then on the fields you want to make hidden you'd do something like this:

    $options = get_options('OPT_NAME');
    $field = array(
        'id'       => 'textarea_id',
        'type'     => 'textarea',
        'hidden'   => ( $options['test_value'] == 1 ) ? true : false,
        'title'    => __( 'Test Hidden Field', 'redux-framework-demo' ),
        'desc'     => __( 'This field will be set to be hidden if text_value is 1.', 'redux-framework-demo' ),
    );
    

    It's pretty strait forward. I hope that helps! You can also apply the hidden argument to sections as well. ;)