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