Hack: Show Post List In Alphabetical Order

By default a list of posts will appear with the most recent one on top and the rest in descending chronological order. But if you have a need to show the list in alphabetical order, then you can change that in the pre_get_posts hook. One example may be a glossary. Another may be like the one-page site I created the other week.

In this function, which you can add to functions.php or your own custom plugin, the order is changed to alphabetical by title, and ascending. This is done only on the front page by using the is_front_page function. You can also use is_category for it to work on any category page.

// show posts by title order, not date
add_action('pre_get_posts', 'wpaction_change_order'); 
function wpaction_change_order($query) {
	if (is_front_page()) {
		$query->set('order', 'ASC');
		$query->set('orderby', 'title');

If you are looking to sort by something else, here is the documentation for orderby.

Leave a Reply

Your email address will not be published. Required fields are marked *