Created
November 13, 2019 08:48
-
-
Save eksiscloud/1ca1e88a2d0e6ce9d8b6e66d94a351c4 to your computer and use it in GitHub Desktop.
Wordpress archives of posts: Alphabetically order
This file contains 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 custom_pre_get_posts($query) { | |
// validate | |
if(!is_admin() && $query->is_main_query()) { | |
if(is_archive()) { | |
$query->set('orderby', 'title'); // order posts by title | |
$query->set('order', 'ASC'); // and in ascending order | |
} | |
} | |
} | |
add_action('pre_get_posts', 'custom_pre_get_posts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment