Test for values in WordPress custom field shortcode
You can use a conditional shortcode to test a text or integer value returned by the shortcode for a WordPress custom field.
For example, you can test a shortcode with a statement such as "If the value of this shortcode is "coffee" then display this text, or else display this other text," or "If the value of this custom field shortcode is less than 2, then display this text or else display this other text."
The syntax is the same as for the Boolean-If and the if-else conditionals shortcode statements, with extra parameters:
Display this text when the value test is true.
[wpbb-else]Display this text when the value test is false.
The exp parameter is the operator, with the following values:
For text strings, you can use the following operators:
For integers, you can use the following operators:
The value parameter is the value that you want to test for. This can be a text string or an integer. Note that you can test for a date value as long as it is in the form YYYYMMDD, so the value can be compared as an integer.
The following examples are written so the actual value in the post being previewed is displayed for comparison. These examples are based on three WordPress custom fields with the following names:
Custom WordPress fields don't have data types, but these three fields were named for testing purposes to indicate what the value would be: a text string, an integer, or a date in the format YYYYMMDD.
This code was inserted into an HTML module in a Singular Themer layout to test values for WordPress custom fields that had been added to those posts. Look at the output in each example to help understand the code.