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
ACF Flexible Content Field – Layout Labels and Sub Field Labels

ACF Flexible Content Field – Layout Labels and Sub Field Labels

How to output the text of layout labels and/or sub field labels using the Flexible Content field of ACF Pro.
Categories:
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
How to Update Custom Fields with Default Values For Existing Posts when using ACF

How to Update Custom Fields with Default Values For Existing Posts when using ACF

Let's take a scenario where there are 10 Pages in a WordPress site. You proceed to create a Text-type of custom field called, say, "Custom…
Categories:
Tags:
Pro
Limit Bricks Users Query to Current Post’s User-type ACF Field Value

Limit Bricks Users Query to Current Post’s User-type ACF Field Value

Consider this scenario with ACF: "John Briley" user: "Gandhi" movie: The requirement is to show John Briley as the author when Gandhi movie item is…
Categories:
Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories:
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: