-
-
Save andrasguseo/60cd347b4cb9e6cd70d10f64152e601a to your computer and use it in GitHub Desktop.
Modify event archive query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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