Title: sort multiple posts from same parent category by subcategory
Last modified: August 19, 2016

---

# sort multiple posts from same parent category by subcategory

 *  [gabyvazquez](https://wordpress.org/support/users/gabyvazquez/)
 * (@gabyvazquez)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/sort-multiple-posts-from-same-parent-category/)
 * My posts are being pulled on to a page based on categories using
 *     ```
       <?php
        if (is_page('3') ) {
       $cat = array(6);
       } elseif ( is_page('19') ) {
       $cat = array(10);
       } elseif ( is_page('202') ) {
       $cat = array(12);
       } elseif ( is_page('17') ) {
       $cat = array(7);
       } elseif ( is_page('204') ) {
       $cat = array(13);
       } elseif ( is_page('23') ) {
       $cat = array(8);
       } elseif ( is_page('9') ) {
       $cat = array(21);
       } else {
       $cat = '';
       }
   
       $showposts = -1; // -1 shows all posts
       $do_not_show_stickies = 1; // 0 to show stickies
       $args=array(
          'category__in' => $cat,
          'showposts' => $showposts,
          'caller_get_posts' => $do_not_show_stickies
          );
       $my_query = new WP_Query($args); 
   
       ?>
       		<div id="colLeft">
       	<?php if( $my_query->have_posts() ) : ?>
   
       		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
   
       <?php
       			//necessary to show the tags
       			global $wp_query;
       			$wp_query->in_the_loop = true;
       			?>
       ```
   
 * After it will display the posts, based on how I have formatted them.
 * My question is.
 * How is it possible to sort the posts withing my query based on the subcategory
   and then display the name of the sub catergory before those set of posts are 
   shown.
 * example:
 * Microphones (display Subcategory name as title)
    Posts (all posts with microphone
   as subcategory)
 * Mixing Boards (display Subcategory name as title)
    Posts (all posts with Mixing
   board as subcategory)
 * All my subcategories are linked to the same Parent category, in this case equipment.
 * Did I lose anyone?

Viewing 1 replies (of 1 total)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/sort-multiple-posts-from-same-parent-category/#post-1414513)
 * Closing this thread.. as a duplicate to the newer topic.
    [http://wordpress.org/support/topic/372794?replies=1](http://wordpress.org/support/topic/372794?replies=1)
 * Please keep similar questions in a single thread.

Viewing 1 replies (of 1 total)

The topic ‘sort multiple posts from same parent category by subcategory’ is closed
to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [subcategory](https://wordpress.org/support/topic-tag/subcategory/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/sort-multiple-posts-from-same-parent-category/#post-1414513)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
