Order a WordPress custom post type archive or taxonomy archive alphabetically.
//order funding alphabetically
// Order custom post types alphabetically
function owd_post_order_nonprofits( $query ) {
if ( $query->is_tax('npregions') && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'owd_post_order_nonprofits' );
function owd_post_order_schools( $query ) {
if ( $query->is_tax('regions') && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'owd_post_order_schools' );
function owd_post_order_grants( $query ) {
if ( $query->is_post_type_archive('grants') && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'owd_post_order_grants' );