Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Created November 13, 2019 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eksiscloud/1ca1e88a2d0e6ce9d8b6e66d94a351c4 to your computer and use it in GitHub Desktop.
Save eksiscloud/1ca1e88a2d0e6ce9d8b6e66d94a351c4 to your computer and use it in GitHub Desktop.
Wordpress archives of posts: Alphabetically order
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