5th Aug '22
/
8 comments

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 BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
ACF Repeater sub field value dynamic data condition in Bricks

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro)…
Pro
Meta Box Image Advanced Field Images in Bricks Query Loop

Meta Box Image Advanced Field Images in Bricks Query Loop

Updated on 3 Feb 2025 A user asked: Do you know what the best way to query an image from metabox gallery? I would like…
Categories:
Tags:
Pro
Showing a Popup conditionally in Bricks based on Query Parameter

Showing a Popup conditionally in Bricks based on Query Parameter

Here's two ways a Bricks Popup can be shown on page load depending on URL parameter value.
Categories:
Tags:
Checking if Repeater/Cloneable Meta Fields Are Empty in Bricks

Checking if Repeater/Cloneable Meta Fields Are Empty in Bricks

Creating a condition to ensure that a section only gets output if at least one row of data is filled in.
Categories:
Pro
Custom Meta Box Thumbnail Slider in WordPress

Custom Meta Box Thumbnail Slider in WordPress

This Pro tutorial provides the steps to set up an image and YouTube video thumbnail slider in WordPress using Splide and Meta Box. The site…
Categories:
Tags:
Pro
Checking ‘PublishPress Future’ plugin’s Future Action enabled posts

Checking ‘PublishPress Future’ plugin’s Future Action enabled posts

PublishPress Future is a handy plugin for scheduling actions like unpublishing or deleting posts (of any post type) at a specified date and time in…
Categories: