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

How to Conditionally show a Repeater or another Element in Oxygen

Sridhar Katakam

In the WPDevDesign Facebook group a user asked:

Just wondering if its possible to have a message/content to appear when a repeater is empty?

To explain: The client's site has an Employment page. I've made a CPT and each new job is it's own post. The repeater on the static Employment page displays all jobs available. Nice and simple, works well.

However, there will be times when the client won't have jobs listings, so instead of a blank page because the repeater won't find any job posts, I would like to display a message.

This members-only tutorial provides the steps to define a custom function that returns the number of published posts of a specified post type and use this in the built-in Dynamic Data condition of Oxygen to either output a Repeater or a Text component depending on whether there is at least one published entry.

Repeater outputting post titles when there is at least 1 portfolio item
A custom text message when there are no portfolio items

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: Get number of published entries for a given post type

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