Skip to content

Instantly share code, notes, and snippets.

@schutzsmith
Created July 12, 2022 15:00
Show Gist options
  • Save schutzsmith/147f62526d11c823385c882e78ecf045 to your computer and use it in GitHub Desktop.
Save schutzsmith/147f62526d11c823385c882e78ecf045 to your computer and use it in GitHub Desktop.
Override taxonomy archive query in WordPress
function wpdev_156674_pre_get_posts( $query ) {
if (
$query->is_main_query()
&& $query->is_tax( 'region' )
) {
// Manipulate $query here, for instance like so
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'meta_key', 'event_date' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'wpdev_156674_pre_get_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment