posts – Hide Past Events from Displaying – AIT Themes Events & Events Pro Plugin


I am using AIT Themes City Guide and trying to configure the Events list to make sense. The theme plugin does not age out old events. I assumed this would be the bare minimum a plugin claiming to be an Event manager would offer. However, it seems I have to make this happen myself. Before you suggest it, the theme developer is not likely to be helpful. Despite having a full license, they have no plans to add this simple feature.

So, I would like to code this myself and the code would have universal benefits. Essentially, events in this theme are “formatted posts”. So, writing code to hide past events could be as simple as the code I found on this page:

How can I hide posts that are over 2 years old

Here is the code suggested:

add_action( 'pre_get_posts', 'filter_old_posts' );
function filter_old_posts($query){
    if( !is_admin() && $query->is_main_query()){
         add_filter('posts_where', $callback = function( $where=""){
             $where .= " AND post_date > '" . date('Y-m-d', strtotime('-2 years')) . "'"; 
             return $where;
         add_filter('getarchives_where', $callback );

How can I modify the above to filter out posts older than the current date? How can I filter out just a single category?

Thank you!!

Vince Dimanno 2 years 2021-04-23T15:21:04-05:00 0 Answers 0 views 0

Leave an answer