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

Related Tutorials..

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:
Pro
MB Favorite Posts in Bricks

MB Favorite Posts in Bricks

This tutorial explores using MB Favorite Posts in Bricks, including outputting the list of favorites via a query loop.
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
Filtering Bricks Query Loop By Meta Box Relationship

Filtering Bricks Query Loop By Meta Box Relationship

In the Bricks Facebook group a user asks: Consider this setup: CPTs: Service Areas and City Pages Meta Box Relationship: City Pages to Service Areas…
Categories:
Pro
Meta Box Relationship Posts Filtered by a Taxonomy Term in Bricks

Meta Box Relationship Posts Filtered by a Taxonomy Term in Bricks

Updated on 17 Feb 2025 In the Inner Circle a user asks: Hello, I have a relationship made in metabox between two Post Types “Travel”…
Categories: