Skip Navigation

[Resolved] Using META Query in Bricks to filter by date.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 1 month, 1 week ago.

Assisted by: Nigel.

Author
Posts
#2689374
Screenshot 2024-03-24 at 2.58.32 p.m..jpg
Screenshot 2024-03-24 at 2.46.20 p.m..jpg

I am experimenting with the linked site as a rebuild using Bricks. I have the option of using the original views or, implementing the loop natively in Bricks.

To filter to just the next concert in the original view I vae it set up to query against an event date/time field where if the event is older than TODAY it wount show and the next concert in the listings is displayed, till all are complete and then there is just a message wait for the next seasons listings.

I have been able to build out the same loop in Bricks where just one item is listed but am having issues figuring out how to filter on the date time field. I have looked at the following Bricks forum in how somebody is doing this with ACF, which is a bit more integrated than Toolset.

hidden link

Here is a screen shot of the Meta Query filter setup where {ts_event-date-time} is the custom field. And also how it is configured in Toolset. I note that in Toolset the format/type is string.

From a brief look over the Bricks forum there needs to be parity in how the date-time formatter is set. Do we now what TODAY is in code format?

Any advice appreciated.

#2689439

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Stephen

Toolset dates fields are stored as timestamps (the number of seconds since 1 Jan 1970), and any date comparison to filter posts by custom date fields must also be as timestamps, to compare like-with-like. Hence in the View filter, TODAY refers to the timestamp for today (at 00:00).

In which case you are actually comparing numbers (integers).

If you are using something else to generate the query (in this case, Bricks), then the meta value you should be comparing against should be a timestamp (the PHP function time() would generate the current timestamp, for example).

#2689449

Thanks Nigel,

If I am reading you correctly, I need to run a php function that queries time() to return an interger for the current time and then compare this to the value in my event-date-time field?

#2689465

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

From your Bricks screenshot, the meta value comes from "date(TODAY)", and I note a lightning symbol, which I guess means the value can be dynamic, perhaps from a PHP statement, or a custom function.

I was suggesting you replace date(TODAY) with such a statement or function, if it is the case that Bricks allows you to put a function or statement there.

And, yes, whatever you use, it needs to return a timestamp.

#2689467

Thanks Nigel. I will experiment and see how I get on. If all fails I can fallback on the Views I have already built for all this but I have a number of concerms.

1.  I see in the DOM that all Toolset Views are preceded by a wrapping div containing a lot of data attributes which is avoided if using a purely Bricks approach.

2. I feel like one of the last of the holdouts by still using Toolset. I have to admit that I am looking at alternatives for the future and, for current sites migration tools for something like Met Box. I'd rather stick with Toolset because from what I can see, it offers the most extensive featur set when you include the integratoin with maps.

I would love to see some annoucment from the top (Amir) stating some commitment to the plugin. I am sure there is some new features that could be added, just enough to give it that little boost to put iit back in front of potential customers as a viable option.

Stephen Vaughan confirmed that the issue was resolved on 2024-03-25 11:02:45.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.