acf-builder-cheatsheet icon indicating copy to clipboard operation
acf-builder-cheatsheet copied to clipboard

Add example with conditional logic

Open rguttersohn opened this issue 2 years ago • 2 comments

Not sure if I am missing this somewhere, but I can't seem to figure out how to implement conditional logic for a field. I tried:

'conditional_logic' => [ 'include_call_to_action', '==', 0],

and:

[ 'include_call_to_action' => 1],

Neither is working. It would be great to have an example that uses conditional logic.

rguttersohn avatar Mar 28 '23 17:03 rguttersohn

When you have doubts of this type, a good practice is to generate the field with the graphical interface and then export the PHP with the ACF tool. So you can see what the notation is like. Here is an example of conditional logic.

                'conditional_logic' => [
                    [
                        [
                            'field' => 'single_project_type',
                            'operator' => '==',
                            'value' => 'image',
                        ]
                    ]
                ],

aitormendez avatar Mar 28 '23 17:03 aitormendez

That's a great idea. Didn't think of that. I wonder if that tip should be at the top as a catch all? I can make a PR and add it if it seems worth it.

rguttersohn avatar Mar 28 '23 17:03 rguttersohn