Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Last active May 24, 2018 11:27
Show Gist options
  • Save andrasguseo/60cd347b4cb9e6cd70d10f64152e601a to your computer and use it in GitHub Desktop.
Save andrasguseo/60cd347b4cb9e6cd70d10f64152e601a to your computer and use it in GitHub Desktop.
Modify event archive query
<?php
/*
* Modifies the view of categories.
* Events will be shown from newest to latest in descending order.
* Only works on event category views, won't work on month view, shouldn't impact non-event category views.
* Plugins: The Events Calendar
*
* Author: Barry Hughes
* Last updated: July 12, 2017
*/
function modify_event_archive_query( $query ) {
$type = $query->get( 'eventDisplay' );
$event_cat = $query->get( 'tribe_events_cat' );
if ( empty( $type ) || 'month' === $type ) {
return;
}
if ( empty( $event_cat ) ) {
return;
}
if ( ! $query->is_main_query() ) {
return;
}
$query->set( 'eventDisplay', 'custom' );
$query->set( 'order', 'DESC' );
}
add_action( 'pre_get_posts', 'modify_event_archive_query', 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment