Skip Navigation

[Resolved] Trying to use conditional output with repeatable field groups

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

Problem: I would like to test if any RFGs exist on a post, using conditional HTML.

Solution: There's not a way to test that with conditional HTML, but you can use the View's wpv-items-found and wpv-no-items-found sections to display information only if there are RFG results found in the View.

This support ticket is created 4 years, 9 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 7 replies, has 2 voices.

Last updated by chrisC-25 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1272879

I have a repeating field setup called Apple Playlists. I want to only show the view when the repeating fields are not empty. This is the code I used, but it makes the entire view disappear even when there are non empty fields.

[wpv-conditional if="( $(wpcf-apple-playlists) ne '' )"]<div class="btn-group btn-group-view">[wpv-view name="apple-playlists"]</div>[/wpv-conditional]

Thanks

#1272931

Hi, try using the Types field shortcode syntax instead:

 [wpv-conditional if="( '[types field="apple-playlists" output="raw"][/types]' ne '' )"]<div class="btn-group btn-group-view">[wpv-view name="apple-playlists"]</div>[/wpv-conditional]
#1272975

Thanks, that did not work. I added the code to come just before the first button, and it is not showing. See here:
hidden link

#1272981

I'm not quite sure I know what I should be looking for. I see an Apply Playlists button, that includes a View. Just before that I see Oscar Hammerstein and Richard Rogers, as text links. Can you turn on debug mode and tell me if anything is shown on screen?

[wpv-conditional if="( '[types field="apple-playlists" output="raw"][/types]' ne '' )" debug="true"]<div class="btn-group btn-group-view">[wpv-view name="apple-playlists"]</div>[/wpv-conditional]
#1273015

okay, debug is on

here is what it says:
1
####################
wpv-conditional attributes
####################
Array
(
[if] => ( '' ne '' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( '' ne '' )
--------------------
After replacing 1 general variables and comparing strings: ( '' ne '' )
Comparing to

#1273023

So it seems to think the custom field is empty. May I log in and see how this is set up?

#1273029

Oh I see now, you're talking about repeatable field groups (RFGs), not a single repeating field. I misunderstood. There's no way to use conditional HTML to test whether or not there are any RFGs associated with a post. However, you can use the Apple Playlists View like a conditional. There are two sections in a View - wpv-items-found and wpv-no-items-found. You can move your button code inside the wpv-items-found block of the View, just before the wpv-loop tags, and leave the wpv-no-items-found block empty.

#1273039

Ahh, right. Perfect. My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.