Conditional Output based on Date Time Picker Field in Bricks

In the past, we showed how elements can be conditionally output based on a post's Date type of ACF field here.

This Pro tutorial for Bricks users provides the steps for outputting elements depending on whether the value of the current post's custom field of Date Time Picker type created using ACF (might be updated with Meta Box-specific changes in the future) is before or after the current time whilst taking the site's timezone into account.

Let's take an example where "Event Date" for a post is November 20, 2023 5:30 pm. Now you want to output a Section (inside the loop for this post - could be the single post view or in a Bricks query loop) only if the current time is 5:30 pm on Nov 20, 2023 or past that but not before that. This tutorial shows how.

It's a way of saying "I want this thing to go live from this time on this day" with the time and date coming from the post's meta and so could be different from post to post. "Dynamic post meta element scheduling" could be an alternate title for this tutorial.

Note

As of ACF (Pro) 6.2.3 and Bricks 1.9.3, ACF's get_field() and Bricks {acf_field_name} dynamic data tag do not take timezone set in WordPress' settings into consideration in the output. Not sure this is intended or a bug but it is a big gotcha when doing time comparisons. We are going to work around this.

Step 1

At Settings → General, select the city in the same timezone as you.

Step 2

Create your custom field group.

Tip: If you are using get_field() in your code anywhere for outputting DateTime field values with a few lines of code to take timezone into consideration, select Y-m-d H:i:s as the Return format. It is not necessary for this tutorial.

Step 3

Edit your items and populate the field for each.

Step 4

Add the following 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 525 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Upcoming Events Grouped by ‘Month Year’ in Bricks

Upcoming Events Grouped by ‘Month Year’ in Bricks

A custom query loop type for showing future events based on a date custom field using three nested query loops.
How to create a dynamic infinite logo slider with ACF and Bricks

How to create a dynamic infinite logo slider with ACF and Bricks

This tutorial provides the builder settings, PHP & CSS codes that can be pasted in order to create an infinite logo slider in pure CSS…
Pro
Configuring Image Gallery dynamic source in Bricks

Configuring Image Gallery dynamic source in Bricks

Let's say you have a custom field created with ACF Pro of the type Gallery called "Property Gallery" for posts of "Property" CPT. In the…
Pro
Category Grid with ACF Images in Bricks

Category Grid with ACF Images in Bricks

Creating a grid of post categories, each category card showing an image from an ACF field, category name & description.
Categories:
Custom Function for ACF Link Field

Custom Function for ACF Link Field

How to output the label of an ACF link field through Dynamic Data.
Categories:
Tags:
Pro
Featured Image’s Meta in a Bricks Posts Query Loop

Featured Image’s Meta in a Bricks Posts Query Loop

How to output values of custom fields for the featured image of current post in a query loop
Categories:
Tags: