Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sets the default month for the events page to the first month that has event dates.
<?php
/**
* Sets the default month for the events page to the first month.
*
* @return void
*/
public function set_default_month() {
global $wp_query;
global $wp_theatre;
if (
is_page( $wp_theatre->listing_page->page()->ID ) &&
empty( $wp_query->query_vars['wpt_month'] ) &&
empty( $wp_query->query_vars['wpt_day'] ) &&
empty( $wp_query->query_vars['wpt_category'] )
) {
$months_args = array(
'start' => 'now',
);
$months = $wp_theatre->events->get_months( $months_args );
if ( ! empty( $months ) ) {
$months_keys = array_keys( $months );
$wp_query->query_vars['wpt_month'] = $months_keys[0];
}
}
}
add_action( 'wp', 'set_default_month' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.