Problem: I have a repeatable field group that contains several fields. I would like to use a conditional to test if any of the RFG has a value in one specific field. If so, I would like to show some text in a header. If not, I would like to hide the header.
Solution: One way to accomplish this in Toolset alone is with a View of the Repeatable Field Group. Add a post relationship query filter, so that the parent post is set by the current page ( or the current post in the loop if you're displaying the main post in a View ). Then add a Query Filter for the custom field (or fields), and check that the field value is not empty. Set the limit to 1 post, since all you need to know is whether or not one exists. In the wpv-items-found section of the loop, add the heading information you want to display. In the wpv-no-items-found section, delete the text message. This View is now effectively a conditional that tests if any related RFG have content in the custom field(s) in your query filter.
If you need something more flexible, a custom shortcode approach is probably more practical. You can use the toolset_get_related_posts API to get all the RFGs for a specific post, then loop over them and inspect their post meta values. I can help with toolset_get_related_posts if you need more information. Basically an RFG is treated as a child of the main post. The slug of the relationship is identical to the RFG slug.
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
https://developer.wordpress.org/reference/functions/get_post_meta/
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 5 years, 11 months ago.
Assisted by: Christian Cox.