Aleš Sýkora / November 28, 2023 / 0 comments

Bricks: WP Query by ACF Date field

Post summary: If you want to display a post type with the ACF date field assigned to display (for example) events in the future by the date, you should know how to create the query in Bricks. You must set the return value of ACF date field to Ymd Then create the Query to display today’s and…

If you want to display a post type with the ACF date field assigned to display (for example) events in the future by the date, you should know how to create the query in Bricks.

You must set the return value of ACF date field to Ymd

Then create the Query to display today’s and future events

You need to set WP Query for your custom post type and set the orderby and order meta key and order.

You need to set the Meta query to your ACF date field slug in Meta key:

And you are done.

Then create the Query to display past events

You just need to change the Compare type in Bricks Meta query:

And then you can change your order to ascending/descending as you want.

Display date field

If you want to display the date field formatted after you set the return value to Ymd, then you can use this PHP to create a custom function or to use in code module.

<?php
  $date = get_field('date');
  echo DateTime::createFromFormat("Ymd", $date)->format('d.m.Y');
?>

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts