Checking Types Fields

You can test your custom fields defined with the Types plugin for meeting specific criteria.

Testing Types fields with the GUI

To check a Types field with the GUI, select Types Fields as the Data origin. From the second dropdown select the field you want to use in your condition and from the third dropdown select the source of the field.

Types field condition
Types field condition

Testing Types fields with the wpv-conditional shortcode

To test a Types field with the wpv-conditional shortcode remember to add the wpcf– prefix to the field name. The Types plugin appends wpcf– to all field names.

Testing Types fields with the wpv-conditional shortcode
[wpv-conditional if="($(wpcf-price) lt '50' )"]Special price! Join now! [/wpv-conditional]

In case that you want to compare a field from a parent source, the syntax should be similar to the following:

Testing Types fields from parent source
[wpv-conditional if="( $(wpcf-price).id(product) lt '50' )"]The parent product is in special price! Join now! [/wpv-conditional]

 

Checking Custom Fields

In your condition you can also test custom fields created outside the Types plugin:

  • fields added directly using the WordPress GUI
  • fields provided by third party plugins or themes

This is an example custom field created using the WordPress GUI:

f

Testing custom fields with the GUI

All custom fields available in your WordPress site will be listed automatically if you choose Custom Fields for the Data origin in the Conditional output GUI:

Condition for custom field
Condition for custom field

Testing custom fields with the wpv-conditional shortcode

Testing custom fields with the wpv-conditional shortcode
[wpv-conditional if="( $(featured) eq '1' )"] This post is featured. [/wpv-conditional]

In case that you want to compare a custom field coming from a parent post types, the syntax should be similar to:

Testing custom fields from parent source
[wpv-conditional if="( $(featured).id(post) eq '1' )"]The parent post is featured.[/wpv-conditional]

Checking radio fields values

Supposing you have the gender field defined as a radio field with the Types plugin:

you can test for a consultant gender using the following code:

Test consultant gender
Consultant about [wpv-conditional if="( $(wpcf-consultant-gender) eq '1' )"]herself[/wpv-conditional] 
[wpv-conditional if="( $(wpcf-consultant-gender) eq '2' )"]himself[/wpv-conditional]

Using fields together with date filters

In your conditions you can compare your date fields with VIews built-in date and time functions.

If you have your date field defined with the Types plugin, you can check if the current value in that field is the same as today’s or is in the future comparing it with the TODAY() function.

Checking if a date is today

using the GUI

Checking if a date is today
Checking if a date is today

using the wpv-conditional shortcode

Checking if a date is today
[wpv-conditional if="( $(wpcf-free-consultations-due-date) eq 'TODAY()' )"]
Today is the last chance for free consultations. Contact us for more details.[/wpv-conditional]

Checking if a date has already passed

Checking if a date has already passed
[wpv-conditional if="( $(wpcf-free-consultations-due-date) gt 'TODAY()' )"]
We are sorry but  this offer has expired.[/wpv-conditional]

Using fields with math operators

You can use math operators + * / in your conditions, together with numeric values, custom field values and even constants like TODAY().
It is important to understand what syntax to use to make sure the code evaluates the right data type.

The following examples should explain the basics:

Using math operators
[wpv-conditional if="( $(wpcf-budget)*2 lt 400 )"]  
If the wpcf-budget numeric field value MULTIPLICATE 2 is lower than 400  
[/wpv-conditional]
 
[wpv-conditional if="( ($(wpcf-consultant-price-per-hour) -  $(wpcf-discount) ) gt 200  )" ] 
  If the wpcf-consultant-price-per-hour numeric  field value MINUS the wpcf-discount numeric field value are greater than 200
[/wpv-conditional]

[wpv-conditional if="( ($(wpcf-toolset-line)*2 ) eq $(wpcf-toolset-line) + $(wpcf-toolset-line))" ] 
  If the numeric field value of wpcf-toolset-line MULTIPLICATE 2, is equal to the numeric value of wpcf-toolset-line PLUS the numeric  value of wpcf-toolset-line
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-toolset-line)*2 eq 'TODAY()' )"]
  if the numeric field value of wpcf-toolset-line MULTIPLICATE 2 is equal to TODAY() (a timestamp value, numeric)
[/wpv-conditional]

[wpv-conditional if="( (1485302400 + 31536000) gt 'TODAY()' )"]
  If the result of 1485302400 + 31536000 is greater than TODAY() (timestamp, numeric value)
[/wpv-conditional]

[wpv-conditional if="( 2*2*2 eq 8 )"]
  If 2*2*2 (8) is equal to 8 (simple math syntaxing supported, such as nested (()()) parenthesis. )
[/wpv-conditional]

Also, make sure to follow these rules:

  • Constants should be set inside single-quotes like this: ''
  • Numbers should not be set inside single-quotes like this: ''
  • Calculations to be performed first, should be set inside parenthesis (). You can also nest calculations.
  • Custom fields created with Types should return strings or numeric values. They should not be set inside single-quotes like this: ''

Other examples