20th Nov '23
/
1 comment

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 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Sorting ACF Relationship Posts by Date Meta in Bricks

Sorting ACF Relationship Posts by Date Meta in Bricks

Consider the following setup: CPT: Events ACF Fields:Event Date Information (Group)|__Event Date (Date Picker)Pick Sub Events (Relationship) An Event can have 1 or more related…
Pro
ACF Taxonomy Field Value in Single Posts

ACF Taxonomy Field Value in Single Posts

Consider this scenario: CPT: Movie Movie CPT Taxonomy: Movie Genre Movie Genre Taxonomy's field: Genre Color Each movie will have only genre set. The requirement…
Categories:
Tags:
Pro
Merging ACF Gallery Images with Featured Image in Bricks

Merging ACF Gallery Images with Featured Image in Bricks

Updated on 12 Mar 2025 In the Bricks Facebook group a user asks: Merging images from different fields into a single gallery Hi, I have…
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…
Modifying ACF Field Value Before It Is Output

Modifying ACF Field Value Before It Is Output

Consider the scenario where a Page has a "Page Fields" field group created with ACF Pro like this: Field name: scientific_coordinators (type Repeater)|__ Sub field…
Categories:
Pro
Testimonials Slider in Bricks

Testimonials Slider in Bricks

Setting up a dynamic testimonial slide that pulls the data from a CPT's post fields and custom fields.
Categories:
Tags: