Is there any way to order posts by category name?

I tried

$args = array(
    'post_type' => 'dlm_download',
    'posts_per_page' => 10,
    'paged' => $paged,
    'order_by'=> 'cat', 
    'order' => 'ASC'

But it does not really work, could please someone give me a hint?


I had the same struggle like you, thank i sat down and rethought the whole thing, what you actually need to is select all the categories, and pass the category id to it.

Since you use a dlm_download you will need to do the following, get the terms from the dlm_download_category

$cats = get_terms('dlm_download_category');

Loop trough the category and pass query_posts in it


foreach ($cats as $cat) 

$args = array(
'post_type' => 'dlm_download',
'dlm_download_category' => $cat->slug,


if (have_posts()) : 
while (have_posts()) : the_post(); 
// your stuff here

And there you go

PS: if you want to make it with posts not with custom post

Than $cats = get_categories();

and pass 'cat' in to the argument.

Hope its clear and helps. Cheers

| improve this answer | |

The problem here is that you could have multiple categories assigned to a single post. In that case, which category is the order based off of?

One work around would be to create a script that stores the category name in a meta value, and use the orderby=meta_value to create the proper order.

| improve this answer | |
  • Sounds good at first but, since the actual posts will have multiple categories that's the main problem. If i would do a script selecting all the categories, will generate huge page load and sounds a bit pointless, i tested with one category actually with meta_value still does not work – user1512390 Apr 25 '14 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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