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?

1 Answer 1


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 );
  • You are right Rilwis. But it will only work with custom query and not with Query_posts or Wp_query.
    – swtshweta
    Commented Sep 3, 2012 at 11:48
  • 2
    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.
    – Anh Tran
    Commented Sep 3, 2012 at 14:52
  • I tried this too, but it didn't worked for me. Can you give me some example for this?
    – swtshweta
    Commented Sep 5, 2012 at 4:39
  • Just updated my answer with example. The orderby value should be name instead of post_name. My fault.
    – Anh Tran
    Commented Sep 5, 2012 at 5:03
  • 1
    And note that WP_Query defaults to 'order' => 'DESC' so you might want to explicitly add 'order' => 'ASC'. Commented May 17, 2017 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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