Essential Grid - Filter posts by custom meta data and date()

Hello,

I created some metadata for my posts.
One of this meta data is a date for an event (not the date of the post).
I allready have the posts ordered by this custom meta data, and is working fine.
Now i wanted to show only the events (posts) whose date is later than the current date.
Is this possible?
Thanks in advance,

     Nuno Marques

Hi There,

Thanks for writing in!

Please check this guide for your possible solution.
https://www.themepunch.com/essgrid-doc/custom-meta-data/

Hope this helps!

Thanks

Thank you for your reply!

The steps on the tutorial i’ve allready done sucessfully.
I have a custom meta data with the date of my event and i can show it without any problems.
But now i need a way to show only the events wich date is still to come… for example i don’t want to show a post with an event date that allready passed away.
Don’t know if i made my doubt clear…
Thanks in advance,

       Nuno

Hi nualexan ,

Please add this code snippet to functions.php file in your child theme directory, if you don’t have child theme configured, please follow this guide:

function eg_mod_query($query, $grid_id){
 
if($grid_id == 2){
$query['meta_query'] = array( 'key' => 'eg-date', 'value' => date("Y-m-d"), 'compare' => '>=', 'type' => 'DATE');
$query['meta_key'] = 'eg-date';
}

return $query;
 
}

Two things here you need to modify, the first one is the $grid_id value, change this one to the Grid ID you have, please check this screenshot:

Secondly, the meta key name eg-date, you must replace date with your current custom field name.

Also, make sure to enter the date in YYYY-MM-DD formate in your custom field, for example: 2018-04-10 for today.

Check this guide as a reference.

Thanks.

Thank you Alaa,

With some modifications (name of the fields and date format) i achieved the goal!
Thanks a lot.
Best regards,

   Nuno

Glad you sorted things out and we are delighted to assist you with this.

Cheers!

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