Skip Navigation

[Resolved] Using repeatable groups in conditional field display

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

Problem: I would like to use conditional HTML to show or hide content depending on whether or not there are any entries in the repeating field group associated with the current post.

Solution: There's no syntax in a conditional to check for the existence of entries in a repeatable field group, but you can use a View instead:
- Create a View of this RFG and add a post relationship filter where the parent is set by the page where this View is displayed.
- Set a limit of 1 result, since that's all you need to know.
- In the Loop Editor, click "Skip Wizard" since you don't need to build a Loop.
- In the wpv-items-found tags, include Views shortcodes or Types shortcodes necessary to display content when results are found. If you want to display information from the parent post instead of the RFG, use the id="$current_page" option in the field shortcode like this:

[types field="your-field-slug" id="$current_page"][/types]

- Insert the View in the current post template.

100% of people find this useful.

This support ticket is created 6 years, 2 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Twig 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1110517

I'm trying to use the following conditional logic and can't get it working:

IF the current post has ANY entries in a repeatable field group THEN show a certain field. If it does not, then hide a certain field.

Is this possible, and if so - what is the syntax? I tried $(repeatable-field-group-name) eq '' (and other variants) but they didn't work. I think the test is basically "is the length of the array of field group items zeo" but i don't know how to write that.

I want to use similar logic in a View to display some data:

IF the current post has ANY entries in repeatable field group, THEN display some values. etc.

Is this possible?

Thanks!

#1110749

IF the current post has ANY entries in repeatable field group, THEN display some values. etc.
There's no syntax in a conditional to check for the existence of entries in a repeatable field group, but you can use a View instead:
- Create a View of this RFG and add a post relationship filter where the parent is set by the page where this View is displayed.
- Set a limit of 1 result, since that's all you need to know.
- In the Loop Editor, click "Skip Wizard" since you don't need to build a Loop.
- In the wpv-items-found tags, include Views shortcodes or Types shortcodes necessary to display content when results are found. If you want to display information from the parent post instead of the RFG, use the id="$current_page" option in the field shortcode like this:

[types field="your-field-slug" id="$current_page"][/types]

- Insert the View in the current post template.

Other solutions are possible with custom code.

#1110754

Thanks Christian - I have the View approach working for displaying field content; so to confirm, there's no way to use RFG in a conditional to display a Field that is attached to a custom post type?

#1111524

there's no way to use RFG in a conditional to display a Field that is attached to a custom post type?
There's no way to use RFG in a conditional to display a Field that is attached to a custom post type.

#1113062

Thanks for the info. Related question - I have a lot of RFG info to import (around 200 entries) and I'd rather not do it manually. In the postmeta table, I can see the RFG posts (as a custom post type) but I can't see how they get related to the parent post ( the page that contains the RFG).

How are these connected, and how could I import a bunch of new RFG options directly into the DB?

Thanks

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/import-repeatable-groups/

#1113865

Our support policy states that we address one issue per ticket, so I have split the import question into a separate ticket. I'll follow up there shortly.

#1113869

Thanks for the info