Do you have experience in web development and a passion for writing articles? If so, you might want to contact us. Learn more » http://simonswindows.com/ window cleaning in new york.

WordPress: how to display posts in alphabetical order?

hints&tips

About this article: Posted in: Learned along the way
By: Blockcoder ( Admin ) / 04.09.2013
Stats: Comments Off / Views: 295
Tags: , ,

Simple problem

Helou, ever thought how to display posts in alphabetical order with WordPress? Yes, by default, WordPress displays posts in descending and chronological order. Well, there are different WordPress methods to list posts in alphabetical order.


Configuring The Loop!

I assume you are aware of that you can set your own settings to the WordPress Loop and list the posts the way you want. Simpliest solution to the alphabetical order is that you set the argument “orderby” to “title”. But, what do you do for example if you want to list all posts alphabetically from specific category (eg. “books”) in descending order (newest first)? Let’s make that happen!

$args = array(
        'category_name' => 'books' // category "books"
        'orderby' => 'title', // alphabetical order
        'posts_per_page' => '-1', // gets all posts
        'order' => 'DESC'
);
$query = new WP_Query( $args );

There you go. The loop will display all posts from category called “books” in descending order.