You can use conditional shortcode to test a text or integer value returned by the shortcode for a WordPress custom field.
You can also use conditional shortcode to test for the presence or absence of a WordPress custom field value.
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 conditional shortcode statements, with extra parameters:
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:
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.
value parameter is case-sensitive.
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.
notequals test example#
equals test example#
greater test example#