Published on Oct 21, 2020

Dynamic Data Condition in Oxygen based on CPT Post Count

Sridhar Katakam

In the WPDevDesign Facebook group, a user asks:

How do i make this "OXY Toolbox" condition to hide the element if the condition is met.
"CPT has at least 1 Published Entry"
Or
Can i make it so if 0 published entries show this element ?

This members-only tutorial provides the steps to register a custom function that returns the number of published entries of a Custom Post Type specified by its name. This function can then be used with Oxygen's Dynamic Data condition to conditionally output any element (like say, a Section) based on the count of published entries for that CPT. Ex.: only if the CPT has at least 1 published entry or as the user wants in this case - when there are no published entries for this CPT.

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Function] Get the number of published entries in the specified CPT

Code:

This is a premium members-only content.

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

Already a member? Log in below or here.

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