Updated on 17 Nov 2023.
This Pro tutorial shows how we can set
post__in query parameter of a query loop in Bricks to an array of post IDs for which there is at least one date custom field (inside an ACF Repeater) value that is today or in the future.
Update: We also provide the code for the case where all the dates should be today or in the future.
Consider the following scenario:
Field group (json export):
Note that the Return Format for the date-type sub field has been set to
Sample CPT entry with the custom field populated:
Sample entries in our test site as on 19 Oct 2023:
20/10/2023 (future - dd/mm/yyyy format)
26/10/2023, 31/10/2023 (both future)
Output after implementing the tutorial:
If an entry has multiple dates, we are going to code the logic such that only current (today) or upcoming dates are output.
For example, if we change Program 3's dates to be 12 Nov 2021 and 31 Oct 2023 then the output would be:
Let's create a custom function that loops through all the posts of our post type, gets the value of the ACF Repeater field, checks the dates of the date-type sub field for each row and if at least one date value is equal to or greater than today, add that post to the post IDs array.
This is a BricksLabs Pro tutorial.
For full access login below or create your BricksLabs Pro account