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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.