Created
July 12, 2022 15:00
-
-
Save schutzsmith/147f62526d11c823385c882e78ecf045 to your computer and use it in GitHub Desktop.
Override taxonomy archive query in WordPress
This file contains hidden or 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
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