You can test the field connection shortcodes for the following Advanced Custom Fields (third-party plugin) with these operators:
- Text, Email, or Url-type fields
Test if the value equals or doesn't equal a text string you specify.
- Number field
Test if the value equals, doesn't equal, is greater than, greater than or equal to, less than, less than or equal to an integer you specify.
- Radio Button field
Test for the value of the radio button selected.
When you use a value test, make sure the fields you're evaluating have a value. If the field is empty, the value test will always return FALSE.
For example, if you're testing whether the field equals the string "abc" and the field is empty, an
EQUALS test returns
FALSE, and a
NOTEQUALS test also returns
FALSE. The best way to ensure the field has a value is to make it a required field.
The syntax is the same as for the standard Themer Boolean-If and the if-else conditional shortcode statements with extra parameters
In the following example (and the other examples in the following section), the custom field is identified with the standard
post:acf (to identify the field as an ACF),
type (the ACF field type, such as
name (your custom field name), then the
exp option for the operator and the field
value being tested.
For Text, Email, and Url fields, you can use the following operator values for the
For the Number field, you can use the following operator values for the
value parameter is the value that you want to test for.
- When the value of
lessequals, both the Number field value and the value you're testing for in the value parameter are converted to integers before they're compared, but
notequalscompare the exact strings that are there. So, for example, if you're testing whether 377.78 is LESSEQUALS 377.77, the result is TRUE, because both values are converted to 377 before comparison occurs, so they are equal. On the other hand, if you test whether 377.77 EQUALS 377.78, the result is FALSE. because the two strings are being compared as is.
- The EQUALS test for URLs ignores the trailing slash if there is one, in both the field value and the comparison value. For example, https://example.com and https://example.com/ will return TRUE to the EQUALS test.
valueparameter is case-sensitive.
Examples of testing ACF
The following examples of conditional shortcode statements were inserted into an HTML module in a Singular Themer layout. They were constructed so the shortcode value would be displayed, as well as whether the test for the value is true or false. The following custom fields were created for these tests using the Advanced Custom Fields plugin.
string_value(type Text )
number_value(type Number )
email_address(type Email )
pro_link(type Url, a type only available in the Pro version)
Look at the output in each example to help understand the code.
1. ACF Text field
2. ACF Text field
3. ACF Number field
4. ACF Number field
5. ACF Number field
6. ACF Number field
Remember the EQUALS and NOTEQUALS comparisons don't convert number values into integers first, so the comparison is for an exact match of two strings.
7. ACF Email field
Remember that if a field is empty, both the EQUALS test and NOTEQUALS test return FALSE.
8. ACF-Pro URL
Remember that the trailing slash is ignored in both the field and the comparison values.