Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Forked from barryhughes/temp-fix-bug-97829.php
Last active April 9, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrasguseo/810b8d419e4c5f0ceb80135c90b78c5c to your computer and use it in GitHub Desktop.
Save andrasguseo/810b8d419e4c5f0ceb80135c90b78c5c to your computer and use it in GitHub Desktop.
<?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