Filter custom posts by date from ACF field

Hey guys.

I’ve managed to create a calendar by creating a custom post type called ‘Events’ (with CPT UI Plugin), attaching custom fields to it (via ACF), and then creating a Cwicly Query that collects posts from that type and a Cwicly Query Template that actually shows the information gathered.

The most important added ACF-information is ‘Event Date,’ as that shows the date an event will happen in real life.

I now want to create a select filter so that clients can click one of a couple upcoming months, and then see only the events for that month. But of course this needs to be based on the ACF Event Date, not Wordpress Publish Date.

How should I do this?

I’ve tried ordering by date in the query but then I think it’s only collecting the Wordpress publish date…

This is the page:
www.borisbishop.com/agenda

Through a meta query with as meta key the slug of the ACF field containing the event date, coupled with a meta value of Wordpress URL, I’ve now managed to create a search bar that returns posts if you get the exact date right. So inputting ‘20221119’ returns 1 post.

Anyone an idea how I can now get to returning all posts within a range of 2 data entries?


I’ve now found the solution:

Use meta compare ‘BETWEEN’ so that when you feed the query 2 numeric inputs through the filter (20220101,20220131) it includes everything between these two values.

1 Like

Super solution @boris!

You can then add these as options in the Filter block and select the type of your preferred select input.

Example:

1 Like

Yes this is how I’ve got it set up now:


The only problem now is styling the buttons when active. The relative styling tag for an active tab (cc-tab-active) doesn’t seem to work here (when I tried ‘cc-button-active’)

You would need to target the .selected with relative styling from the Filter block directly targeting your button (.selected .yourclass)

i’m really sorry to ask for this much and tell me if I need to create a different topic for this as it’s unrelated to the issue above, but I do not understand what you’re saying.

Are you saying I should apply the relative styling to the filter block or the buttons that I’ve put inside it? And when I’ve done so, should I add as class ‘.selected.mybuttonclass’?

Sorry for not being clear enough :slight_smile:
We will be making this part of the filtering simpler in the coming months (and less opinionated).

The Button Single is basically a repeated <button> element that contains your inner blocks (label etc…).
That <button> element has the class .selected applied to it whenever it is selected.

If you want to add the relative style from the Filter block itself, the rule will be:

If you want to add the relative style from the an inner block, the rule would be: