Conditional Logic
Quick Guide
In this example, we will create a field group with a true/false field and a text field. The text field will only be visible if the true/false field is set to true.
We will start with the following code:
<?php
use JorenRothman\ACFBuilder\FieldGroup;
use JorenRothman\ACFBuilder\Fields\Choice\TrueFalse;
use JorenRothman\ACFBuilder\Fields\Basic\Text;
$fieldGroup = new FieldGroup('My Field Group');
$trueFalse = new TrueFalse('My True False Field');
$textField = new Text('My Text Field');
$fieldGroup->addField($textField);
We will now create the conditional logic and add it to the text field:
<?php
use JorenRothman\ACFBuilder\FieldGroup;
use JorenRothman\ACFBuilder\Fields\Choice\TrueFalse;
use JorenRothman\ACFBuilder\Fields\Basic\Text;
use JorenRothman\ACFBuilder\FieldConditionalLogic;
$fieldGroup = new FieldGroup('My Field Group');
$trueFalse = new TrueFalse('My True False Field');
$istrueFalseTrue = new FieldConditionalLogic();
$istrueFalseTrue->and($trueFalse, '==', true);
$textField = new Text('My Text Field');
$textField->setConditionalLogic($istrueFalseTrue);
$fieldGroup->addField($textField);
Conditional Logic Operators
The following operators are available:
Operator | Description |
---|---|
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
There are many more operators available, but these are the most common ones.
To see all available operators, check out the ACF documentation (opens in a new tab).