Scenario:

Custom Post Type: event
Custom field: event_date (Date Picker type)

In an earlier tutorial titled Show Only Future Events (CPT) with the Repeater in Oxygen, David showed how pre_get_posts can be used to limit the entries of event post type to only those that have their event_date value higher than today so that only future events can be shown.

In this premium tutorial, we shall extend the above to define a custom function that returns the number of future events so that it can be used with the built-in Dynamic Data condition of Oxygen.

This will enable us to output the future events Repeater only when there is at least one future event and optionally show a "There are no upcoming events" text message/heading when there are none.

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Function] Get the number of future events

Code:

This is a premium members-only content.

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

Already a member? Log in below or here.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: