Querying Posts by Date/Datetime Custom Fields in Bricks

This Pro tutorial shows how to configure ACF and Meta Box to query posts in Bricks by custom field(s) of the type Date/Date Time Picker when using ACF or Date/Datetime when using Meta Box.

Update on 16 May 2023: Display posts only from today and in the future - Show only the posts whose date-type custom field's value is today or in the future

Update on 24 Jan 2023: This tutorial has also been tested with a Date type of field created using Pods and is confirmed to work.

Let's take an example of a testimonial custom post type with banner_start and banner_end custom fields of Date or type.

The process is the same regardless of which custom fields plugin is used.

The objective is to pull all the testimonials for which banner_start is equal to earlier/less than/before now AND banner_end is equal to or later/greater than/after now i.e., basically show the banners which are relevant at the current moment in time.

So our meta query should be like this:

banner_start <= current_time && banner_end >= current_time

ACF

Display and Return Formats do not matter and can be left at their default or set to any.

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 526 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.
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
Pro
Meta Box Color Picker to CSS Custom Property Workflow in Bricks

Meta Box Color Picker to CSS Custom Property Workflow in Bricks

This Pro tutorial provides the steps to declare a custom property (CSS variable) whose value is equal to the post-specific color set via a custom…
Categories:
Tags:
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
Google Maps JavaScript API in Bricks

Google Maps JavaScript API in Bricks

This Pro tutorial provides the steps to show post-specific maps with custom marker content in Bricks using Google's Maps JavaScript API and Advanced Custom Fields.…
Categories: