Translation - Μετάφραση

Resources, Technical Assistance and Technology News => Translator resources => Tips on Using Computers => Topic started by: spiros on 03 May, 2022, 14:29:03

Title: Sort WordPress Archive View in Alphabetical Order by Name
Post by: spiros on 03 May, 2022, 14:29:03
Sort WordPress Archive View in Alphabetical Order by Name

Add to your wordpress theme functions.php file

Code: [Select]
add_action( 'pre_get_posts', 'my_change_sort_order');
    function my_change_sort_order($query){
        if(is_archive()):
         //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
           //Set the order ASC or DESC
           $query->set( 'order', 'ASC' );
           //Set the orderby
           $query->set( 'orderby', 'title' );
        endif;   
    };