12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on May 25, 2020

[Video] Conditionally outputting an element if at least one entry has a custom field of a specific value in Oxygen

Sridhar Katakam

This members-only tutorial provides the steps to define a custom function that takes in a post type, custom field name, and the corresponding custom field value as parameters and returns either true (1) or false ('') depending on whether at least one of the entries of the given post type has the given value for the given custom field.

Sample Use Case: Let's say you have an event CPT with an associated radio button type of custom field called event_free_ticket that can either have a value of yes or no. Now you want to display 3 events in a Repeater that is inside a Section and output the Section only if at least one of the three events have event_free_ticket set to yes.

Add the custom function given below as a Code Snippet and use the built-in Dynamic Data condition's PHP Function Return value on the Section while specifying the function name and the arguments.

Code Snippet title: [Function] At least one entry has specific custom field value

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right