Created
April 2, 2018 22:36
-
-
Save barryhughes/44a277f7472ba633db1ee2ea0f91c60f to your computer and use it in GitHub Desktop.
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 | |
function ecp_fix_tag_order( $sql, $query ) { | |
// Only modify the main query, if it is a tag archive query | |
if ( ! $query->is_main_query() || ! $query->is_tag() ) { | |
return $sql; | |
} | |
$has_event_start_date = (bool) strpos( $sql, 'AS EventStartDate' ); | |
$orders_by_post_date = (bool) strpos( $sql, 'ORDER BY post_date DESC' ); | |
if ( $has_event_start_date && $orders_by_post_date ) { | |
$sql = str_replace( 'ORDER BY post_date DESC', 'ORDER BY EventStartDate DESC', $sql ); | |
} | |
return $sql; | |
} | |
add_filter( 'posts_request', 'ecp_fix_tag_order', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment