50% discount on BricksLabs Pro Membership Lifetime Access. Use coupon: GOBRICKS

Conditionally outputting an element in a Query Loop based on date-type custom field

This Pro tutorial shows how to output an element in a Bricks' query loop only if the value of a date-type of custom field for the current post in the loop is greater than the current time i.e., future/upcoming.

Ex.: You have an event custom post type with event_date custom field and a Query Loop to display the recently published 10 events. At a given time, let's say 2 of these events occur in the future. We want a CTA button to appear only for these 2 events and not the other 8.

Sample query loop structure:

In this example, we have used Meta Box to register a "Date Picker" field with "Save value as timestamp" ticked.

Add this in child theme's functions.php or a code snippets plugin:

This is a Pro members-only tutorial.

To get full access, login below or sign up for a Pro Account

Leave the first comment