Stand with Ukraine. Fight for freedom and democracy

Donate
Troubleshooting //
Fail to Display Future and Past Events in the Listing Grid Widget

Fail to Display Future and Past Events in the Listing Grid Widget

Question

I want to show past/future events in the Listing Grid. How can I do that?

Answer

Firstly, you need to know that to query the Listing Grid by the Date type meta field, you can use Relative Time Formats: https://www.php.net/manual/en/datetime.formats.relative.php

For instance, a CPT “Events” has got the Date type meta field dubbed “event-date”. To show only future events in the Listing Grid, you should set the Posts Query section as follows:

posts query section settings

You can also use Macros here. For that, in the Value field bar click on the Dynamic Tags button and select Macros. 

Then in the Macros Settings pop-up window choose Today from the list.

today macros

Now let’s learn how we can show past events. If you want to output the posts created in the previous month, make sure to set the Posts Query like so:

displaying posts created previously

And that’s how you need to set this section in case you want to display the posts that were created in the last 30 days:

displaying past events

If you use a date field saved as a timestamp, then in the Type drop-down menu, you need to choose the Numeric type of the Meta Query Clause.

date field saved as timestamp
numeric field type

It’s that simple! Just pay attention to Relative Time Formats and use them accordingly.

Was this article helpful?
YesNo
Still need help?
Submit a request