Skip Navigation

[Resolved] Code to check for the presence of a repeated field group

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

Problem:

Check for the presence of at least one item in a repeated field group and conditionally display output if it's true.

Solution:
There are two options you can try:
1) Without custom codes
Create a view to query related "photo gallery" posts,
https://toolset.com/forums/topic/code-to-check-for-the-presence-of-a-repeated-field-group/#post-918163

2) With custom PHP function:
https://toolset.com/forums/topic/code-to-check-for-the-presence-of-a-repeated-field-group/#post-918587

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

This support ticket is created 6 years, 7 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#918136
list of custom fields - conditional code dialog.png
photo gallery - repeatable group.png

Tell us what you are trying to do? I'd like to check for the presence of at least one item in a repeated field group and conditionally display output if it's true. I know through the conditional tags I can compare most custom fields, but the field groups don't show up in the pull-down menu. See "list of custom fields - conditional code dialog.png"; the one repeating field group I have, Photo Gallery, doesn't appear; see "photo gallery - repeatable group.png."

Is there any documentation that you are following? No

Is there a similar example that we can see? No

What is the link to your site? hidden link

#918163

Hello,

The Repeated Field Group feature is based on posts, so you just need to create a view:
1) Query related "photo gallery" posts,
2) Filter by the post type relationship:
https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/#displaying-repeatable-field-groups

3) In the "Loop Editor" section, within shortcode [wpv-items-found] ... [/wpv-items-found]
display something if there is any result.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-found

#918341

Luo, thanks for your response. So does this mean there's no way to use the conditional tag syntax to identify repeatable field groups with no content?

#918587

The workaround I mentioned above does not need any custom codes, and it is possible to use custom codes to check if there is any item in repeated field group, for example you can create a custom PHP function ,check if there is any result:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
toolset_get_related_posts
Query related posts by a set of conditions.

Then use it in the wpv-conditional shortcode:
Using custom functions in conditions
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

For your reference.

#918604

OK, I'll review the links you shared shortly. Thank you, Luo!

#918688

You are welcome.