SOLVED: ACF Meta Query Date between two fields

I am trying to use a Meta Query to show a card in a loop only if the current date is on or between two date fields. I am trying to use the “And” as that seems to make the most sense but only one or the other is working to limit the results.

I have tried several combinations of criteria but so far either I am missing something simple, maybe Bricks standard Meta Queries don’t work this way, or I need to leverage an external custom Meta Query definition.

  • Am I declaring this correctly?
  • Am I asking Bricks to do something it can’t do natively?
  • Do I need to create and use an external Meta Query?

I saw this post https://forum.bricksbuilder.io/t/solved-post-loop-meta-query-by-acf-date-field/2309/6 but I want to use dates between two date fields so that the client can set the start date to show the event banner before the actual start date and then it stops presenting after the end date is reached, without having to go back to the post to turn it on and off for presenting.

If the latter, what are all the steps to use an external query?

I use WPcodebox for my external / include code functionality.

This screenshot show’s my latest attempt:

Hey John,

this is natively possible as long as you make sure that you always have both custom fields (start date and end date) available. If there are cases where there is only a start date but no end date you’d need to use the query_vars hook as it is not possible to create nested meta queries using the query loop builder at the moment.

In your latest attempt screenshot you are checking if the announcement’s end date is before the current date. Which is probably not what you want. You want to make sure that the start date is before (less than or equal) the current date and the end date is after (greater than or equal) the current date.

So if these are our custom event fields…

… you’d nee the following meta query:

Best,

André

Andre,

Thank you sincerely for your time and assistance.

It looks like my logic is working now. I will do some other tests but looking good so far.

Kind regards,

-John

Feels like this stopped working in Bricks 1.9

Now nothing is returned.

I sent creds and a reference to “help”. account

Thanks

Hi @jmcbade ,

As per my email reply, just set the Type to DATE or DATETIME

Regards,
Jenn

Did not solve.

Have you looked at the sandbox site?

This issue is not solved for me yet. I created a sandbox in hopes of understanding a resolution.

May I please have some more help on this?

hi @jmcbade

I did another email reply 5 days ago to check what is the expected result.
Anyway, let’s continue our conversation here.

This was the reply

============

===========

Basically it was only 1 event met your condition on 13 September

Now if you look at your site should be empty as today is 18 September and no single event should show. Please tweak any of your event post type end date to check the result.

Regards,
Jenn

“Basically it was only 1 event met your condition on 13 September”

Ok, yeah. I think it’s is now working as expected. :crazy_face:

Thanks

1 Like