Query Loop Future Filter Plugin

This is the first year in a long time that I haven’t been helping coach my son Noah’s basketball teams. It’s felt a little odd, but I’m pretty out of my depth at the high school level and the team has great coaches. So this year I’ve focused more on the tech and media side of things.

At the beginning of the season I created a website that we can keep the schedule and some player info. I hadn’t built a WordPress website in a while so it was fun to get into the block themes. I created a few custom post types to use the main one for Games. Then using the power of the Query Loop block I can choose to display different sets of games. Most of this is done by filtering by different taxonomies. I have taxonomies for seasons, type of game, Exhibition, Regular Season, a Tournament, etc.

The one thing that was a struggle for me was I had games in the future. To start I wanted people to be able to see games that were in the future, but by default they would be considered scheduled posts, and not public until the date set happened. To get around that I added this snippet of code to my themes functions.php that will take any future posts and set them to be published instead.

function game_prevent_future_type( $post_data ) 
    if ( $post_data['post_status'] == 'future' && $post_data['post_type'] == 'game' )
    {
        $post_data['post_status'] = 'publish';
    }
    return $post_data;
  }
  
  add_filter('wp_insert_post_data', 'game_prevent_future_type');
  remove_action('future_post', '_future_post_hook');

The next issue was that I wanted to be able to show only upcoming games, but there wasn’t a way to do that with with the Query Loop Block. I wanted to add a filter that would allow me to show only future games. Thanks to Misha Rudrastyh I was able to create a plugin that allows to do just that. It can be found on GitHub, the Query Loop Future Filter Plugin.

It won’t be the most common thing someone needs but maybe someone will find it useful.

Leave a comment