Using the Meta Key Filter in The Grid plugin to select only dates in the future

I want to filter some custom posts in The Grid so that only those with an Event Start Date of the current date or later are selected. The custom posts have a DateTime meta key named _EventStartDate which I want to compare with the date, as provided by the Wordpress Date() function. Is this possible? I’ve tried various permutations similar to this one:

If it can’t be done this way, is it possible using a function instead?

Many thanks
Mike.

Hi Mike,

Thanks for reaching out.
You can compare the DateTime meta value with the WordPress date function, just remember that the format should be the same for both the values. If the format is already the same, but it is not working I would suggest you share the login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Thanks, I’ve sent the secure note.

Strangely, when I have saved the grid then opened it up to edit it again, I find that many empty meta key edit boxes have been inserted, like this:

… followed by the condition I entered, but displayed as a concatentated string:

Maybe this is just the way it works - but it is a bit unexpected!

Anyway, the filter is not working the way I want; the first post it returns is in the past.

There’s a page using the grid at https://dev.reachuk.org/fundraising/challenge-events/.

Thanks
Mike.

Hello @mikerayjones,

You are not supposed to insert date('Y-m-h:i:s'). It has resulted in an issue which is why you are seeing other custom meta fields. I went ahead and removed them already. Please have your filter updated and use double quotes: date("Y-m-h:i:s").

Kindly let us know how it goes.

Hi @ruenel.

I went ahead and tried using date(“Y-m-d h:i:s”), like this:

However, the filter still doesn’t work, and when I go back in to edit I see that the issue with many other custom meta fields has happened again.

Thanks
Mike.

Hello Mike,

It seems that the plugin field does not accept single and double-quotes. I have tested these examples with no quotes and it works.


Kindly check your site The Grid plugin now.

Hi @ruenel.

Agreed - the way you have entered it, the other custom meta fields are no longer generated. However, the filter still doesn’t do what I want it to do, which is to exclude the posts that started earlier than today.

If I enter today’s date as a static string, like this:

… then the filter works correctly, and excludes the events that are in the past. So to put it another way, how can I get the current date to be entered dynamically in the Meta Key value field? It feels like I am so close!

Thanks.

Hello @mikerayjones,

I suspect that the field only accepts plain text or number values. It cannot accept a shortcode or the PHP date() function. This is something we can add to our list of feature requests for the enhancements of the plugin. This way it can be taken into consideration for future development. All of these items are discussed with the creators of TheGrid plugin team internally and prioritized based on the amount of interest a particular feature might receive.

Thank you for your understanding.

That’s a shame! OK, thanks for investigating.

You are welcome @mikerayjones

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.