Change Default Sort Order For Posts
Archive Pages For Custom Post Type
This changes sort order to ascending, based on title, for any archive page, with the documentation post type
// for kadence theme and facetwp only on documentation query
add_action( 'pre_get_posts', 'my_change_sort_order' );
function my_change_sort_order( $query ){
if ( ! is_admin() && ( is_home() || is_archive() ) && ( $query->is_post_type_archive( 'documentation' ) ){
$query->set( 'order', 'ASC' );
$query->set( 'orderby', 'title' );
}
}
Archive Pages For Any Post Type
This changes sort order to ascending, based on title, for any archive page, with all post types
// for kadence theme and facetwp only on documentation query
add_action( 'pre_get_posts', 'my_change_sort_order' );
function my_change_sort_order( $query ){
if ( ! is_admin() && ( is_home() || is_archive() ) && $query->is_main_query() ){
$query->set( 'order', 'ASC' );
$query->set( 'orderby', 'title' );
}
}