I've been working on a new website off an on over the last couple of weeks, all in all things have gone fairly well. Indeed some of the things I thought would be a major challenge seemed to come off relatively easily, it's more the things you expect to be trivial that seem to pose more of a problem.

Take for example an events calendar, you would think, well, I would think, that one of the basic requirements would be to list up-and-coming events, and not to show older events.

Sounds relatively straightforward .. so after trying a bunch of Wordpress plugins I settled for "The Events Calendar" by "Modern Tribe Inc.". Nice professional layout, lots of pre-existing users, what could go wrong?!

Heh, no ability to list up-coming events.

Which leaves us with code, and unfortunately Wordpress is all PHP, so much experimentation later this is what I came up with, documented in full here because I know at some point in the future something is going to override the change because I've forgotten that it's not a built-in feature.

function concerts_pre_get_posts( $query ) {
    if ( isset( $query->query_vars[ 'post_type' ] ) && $query->query_vars[ 'post_type' ] == 'tribe_events' ) {
        $query->set( 'orderby', 'meta_value' );
        $query->set( 'order', 'ASC' );
        $query->set( 'meta_query', array(
            array(
                'key' => '_EventEndDate',
                'value' => date( 'Y-m-d H:i:s' ),
                'compare' => '>',
                'type' => 'DATETIME'
            )
        ) );
    }
}
add_filter( 'pre_get_posts', 'concerts_pre_get_posts' );

And this lovely little snippet needs to be inserted into the functions.php in your theme folder. So I suspect that one day I will fall foul of trying to update my template, but for now this appears to give the right result.

Looks fairly obvious when you see it (!) but if you're not a PHP programmer, well, there's a lot to be said for built-in features ... I suspect this might be a problem for anyone interested in looking at historical events, but in this case - not functionality I need.

Website is now up at https://linux.uk