Title: Order posts by specific categories?
Last modified: August 19, 2016

---

# Order posts by specific categories?

 *  [bazel](https://wordpress.org/support/users/bazel/)
 * (@bazel)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/order-posts-by-specific-categories/)
 * I want to order posts that I get from 3 categories (ex A,B,C) in the same order(
   A,B,C). By default I get the newest post first
 * Thanks

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/order-posts-by-specific-categories/#post-1864059)
 * I believe that this code will do what you want:
 *     ```
       function mam_posts_join ($join) {
          global $mam_global_join;
          if ($mam_global_join) $join .= " $mam_global_join";
          return $join;
       }
       function mam_posts_orderby ($orderby) {
          global $mam_global_orderby;
          if ($mam_global_orderby) $orderby = $mam_global_orderby;
          return $orderby;
       }
       add_filter('posts_join','mam_posts_join');
       add_filter('posts_orderby','mam_posts_orderby');
   
       $mam_global_join = " INNER JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)";
       $mam_global_orderby = " UPPER($wpdb->terms.name) ASC, $wpdb->posts.post_date DESC";
       query_posts('cat=32,65,58&posts_per_page=20');
       ```
   
 * Of course, you need to supply your own categories and posts_per_page.

Viewing 1 replies (of 1 total)

The topic ‘Order posts by specific categories?’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/order-posts-by-specific-categories/#post-1864059)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
