Answers for "order by pre get posts"

PHP
0

order by pre get posts

add_action( 'pre_get_posts', 'standout_sort' );
function standout_sort( $query ) {
    if ( $query->is_main_query() && !is_admin() && is_post_type_archive('team') ) {
        $query->set('orderby', 'meta_value_num');  
            $query->set('meta_key', 'sort_order');  
            $query->set('order', 'ASC'); 
    }
}
Posted by: Guest on December-11-2020

Browse Popular Code Answers by Language