-
-
Save andrasguseo/810b8d419e4c5f0ceb80135c90b78c5c 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( 'LIMIT', 'ORDER BY EventStartDate DESC LIMIT', $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