Skip Navigation

[Resolved] wpv-conditional with field array

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to check if a repeating field has any empty values.

Solution:

This can be done by using the code below.

[wpv-for-each field="wpcf-my-field"]
 
[wpv-conditional if="'[types field='my-field'][/types]' ne '' "]
 
Content goes here if field is NOT empty
 
[/wpv-conditional]
 
[/wpv-for-each]

What the above code will do is to loop through each index of the field then with the conditional checking if that index is empty. Finally replace "wpcf-my-field" with the slug of your image field keeping the wpcf- prefix EXCEPT when it is being called in the types shortcode.

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by davideE-4 3 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#2027443

Hi,
I have a filed wpcf-photo with many values.
Into a wpv-conditional how can I check the first, second, third etc .. photos?
Regards

#2027545

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Do you mean check if each index has a value? You should be able to do it like this.

<o[wpv-for-each field="wpcf-my-field"]

[wpv-conditional if="'[types field='my-field'][/types]' ne '' "]

Content goes here if field is NOT empty

[/wpv-conditional]

[/wpv-for-each]

What the above code will do is to loop through each index of the field then with the conditional checking if that index is empty. Finally replace "wpcf-my-field" with the slug of your image field keeping the wpcf- prefix EXCEPT when it is being called in the types shortcode.

Please let me know if this helps.
Thanks,
Shane

#2027551

Hi Shane,
perfect. But if I wanted to do it only for the first 5/10 photos?
Regards

#2027561

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Sure there is a start and an end attribute for the [wpv-for-each] shortcode. So you will actually do it like this below.


[wpv-for-each field="wpcf-my-field" start="1" end="5"]
 
[wpv-conditional if="'[types field='my-field'][/types]' ne '' "]
 
Content goes here if field is NOT empty
 
[/wpv-conditional]
 
[/wpv-for-each]

Please let me know if this helps.
Thanks,
Shane

#2028193

My issue is resolved now. Thank you!