Skip Navigation

[Resolved] Conditionals and Repeatable Fields

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

Problem: I have a View showing the repeatable field groups (RFGs) for a specific post. Inside the View of RFGs, I would like to create a conditional that tests whether or not the checkbox custom field in the parent post is checked.

Solution:
Use the @repeatablefieldgroupslug.parent syntax in the id attribute of the wpv-post-field shortcode to access the raw value of the checkbox custom field in the parent post. A checkbox field will normally have the value 1 if checked, so your conditional will look like this:

[wpv-conditional if="( '[wpv-post-field name='wpcf-premium' id='@repeatablefieldgroupslug.parent']' eq '1' )"]
Checkbox is checked[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/
https://toolset.com/documentation/customizing-sites-using-php/functions/

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

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1166492

Hello,

I have a CPT with repeatable fields. The CPT has a checkbox "premium" which when is checked (value 1), the fields from repeatable group should be displayed, but it does not work in my case. For displaying CPT I have created Content Template in DIVI in which I put View with the repeatable fields. View has this conditional:

{!{wpv-conditional if="( $(wpcf-premium) eq '1' )"}!}Some field{!{/wpv-conditional}!}

Also I tried to add id with parent or slug of the CPT, but without success: {!{wpv-conditional if="( $(wpcf-premium id='$parent') eq '1' )"}!}Some field{!{/wpv-conditional}!}

If I place shortcodes of the field group without conditionals, they are displayed normally.

#1167246

For displaying CPT I have created Content Template in DIVI in which I put View with the repeatable fields. View has this conditional:

{!{wpv-conditional if="( $(wpcf-premium) eq '1' )"}!}Some field{!{/wpv-conditional}!}

Hi, when selecting a parent post in the conditional GUI, the current software produces some invalid code. In older versions of Types with the legacy post relationship system, "$parent" would have worked. However in the updated relationships system, the best syntax right now is like this:

[wpv-conditional if="( '[wpv-post-field name='wpcf-premium' id='@relationship-slug.parent']' eq '1' )"]
Checkbox is checked
[/wpv-conditional]

You should replace relationship-slug with the slug of your post relationship. You can find this slug by editing the post relationship in Toolset > Relationships. We're still working on implementing the long-term syntax, but the syntax I have provided here should continue to work.

#1167546

Hi,

I have tried the conditional as you recommended, but it does not work. I am not sure, but I think CPT with own CPT´s Repeatable Field Group cannot have relationship between them.

Here is debug for

[wpv-conditional if="( '[wpv-post-field name='wpcf-premium']' eq '1')" debug="true"]Checked[/wpv-conditional]
####################
wpv-conditional attributes
####################
Array
(
    [if] => ( '' = '1')
    [debug] => true
)

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

The same result I get with

[wpv-conditional if="( '[wpv-post-field name='wpcf-premium' id='@spolecnost.parent']' eq '1')" debug="true"]Checked[/wpv-conditional]

I would be happy if you have look into my WP.

#1167935

The slug of the relationship between a post and its own RFGs is the same as the slug of the RFG. I'll be glad to take a closer look if you provide login credentials in the private fields here. Let me know where I can find this conditional on the front-end of your site.

#1169951

Great, glad that worked for you. You are the second person who has told me the submit button didn't work when trying to resolve, so I'm going to ask the team to investigate that. Thanks for letting me know.