WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to display posts sorted by slug on a page. Is it possible to order posts by slug using query_posts or Wp_query?

share|improve this question

In WordPress the post slug is saved in database with name post_name, so to sort posts by slug just use: orderby=name.


Here's the example of query:

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 10,
    'orderby' => 'name'
$query = new WP_Query( $args );
share|improve this answer
You are right Rilwis. But it will only work with custom query and not with Query_posts or Wp_query. – swtshweta Sep 3 '12 at 11:48
What do you mean custom query vs query_posts & WP_Query? If you're using query_posts or WP_Query, that is custom query. And you just need to pass orderby=post_name as a parameter. – Rilwis Sep 3 '12 at 14:52
I tried this too, but it didn't worked for me. Can you give me some example for this? – swtshweta Sep 5 '12 at 4:39
Just updated my answer with example. The orderby value should be name instead of post_name. My fault. – Rilwis Sep 5 '12 at 5:03
Perfect Rilwis...Thanks :) – swtshweta Sep 5 '12 at 12:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.