Support

Account

Home Forums ACF PRO Populate choices to conditional logic Reply To: Populate choices to conditional logic

  • Let’s say you have two simple text fields, and only want Field B to be visible when Field A has a value entered (someone has typed in the field).

    Go to Custom Fields > Tools.

    Select the field that you wish to alter under “Export Field Groups” and then click “Generate PHP.”

    Find the keys of the fields that you wish to manipulate in the resulting PHP.

    The text fields look something like this (I omitted many parts of each array, and simplified what the key will actually look like to make it easier to follow):

    
    array(
      'key' => 'field_645328a8347d',
      'label' => 'Field A',
      'name' => 'field_a',
      'type' => 'text',
      ...
    ),
    array(
      'key' => 'field_645308d746c6',
      'label' => 'Field B',
      'name' => 'field_b',
      'type' => 'text',
      ...
    )
    

    Now you can write your filter function:

    
    function modify_field( $field ){
    
    $field['conditional_logic'] = array( 
      array(
        array(
          'field' => 'field_645328a8347d',
          'operator' => '!=empty',
          'value' => ''
        )
      )
    );
    
    }
    add_filter('acf/load_field/key=field_645308d746c6');