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

Related Tutorials..

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:
Pro
Random images from ACF Options Gallery in Bricks

Random images from ACF Options Gallery in Bricks

This Pro tutorial provides the steps to output images from an ACF Gallery-type custom field in a Bricks query loop randomly with each image appearing…
Categories:
Pro
Custom Meta Box Thumbnail Slider in WordPress

Custom Meta Box Thumbnail Slider in WordPress

This Pro tutorial provides the steps to set up an image and YouTube video thumbnail slider in WordPress using Splide and Meta Box. The site…
Categories:
Tags:
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
Conditional Output Based on ACF Date Field in Bricks

Conditional Output Based on ACF Date Field in Bricks

Updated on 1 Aug 2024 Looking to have a Section or other elements in Bricks rendered on the frontend only if today's date is before…
Categories:
Pro
Dynamic Post-specific Templates in Bricks using Meta Box/ACF Select Field

Dynamic Post-specific Templates in Bricks using Meta Box/ACF Select Field

Update on 23 Aug 2023: Added steps for ACF. Bricks builder v1.8.4 introduced an pretty useful filter called bricks/active_templates that flew under the radar. This…
Pro
Meta Box Relationship in Bricks using Posts Query Loop

Meta Box Relationship in Bricks using Posts Query Loop

This Pro tutorial is similar to the recent ACF Relationship in Bricks using Posts Query Loop guide but for Meta Box. In the past, we…
Categories: