Last active
January 7, 2017 16:53
-
-
Save morgyface/956126549c4a88e8b27fa65fd9dd9125 to your computer and use it in GitHub Desktop.
WordPress | Loop | Order | pre_get_posts
This file contains hidden or 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
| <?php | |
| // This alters the main loop (loop.php) to order Archive queries by Title | |
| function archive_posts($query) { | |
| if ( $query->is_archive() ) { | |
| $query->set( 'orderby', 'title' ); | |
| $query->set( 'order', 'asc' ); | |
| } | |
| } | |
| add_action('pre_get_posts', 'archive_posts'); | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loop change
The main loop.php template just dishes out the posts in date order by default. Here we use pre_get_posts to change the order of the query when it is an archive.
This needs adding to functions.php.