29th Nov '22
/
8 comments

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

Related Tutorials..

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
ACF Repeater sub field value dynamic data condition in Bricks

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro)…
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:
Pro
Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering a query loop to output only those posts with the value of a Select subfield of a Group field set to Yes when using…
Categories:
Tags:
Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

In the past we showed how a Bricks posts query loop can be filtered by Meta Box group's subfield of types text/number and Datepicker here.…
Categories:
Pro
Filtering Cloneable Meta Box Group by Sub Field Value in Bricks

Filtering Cloneable Meta Box Group by Sub Field Value in Bricks

This Pro tutorial provides the steps to filter the rows of a Meta Box cloneable group to only those that have a date custom field…