• 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)
Viewing 1 replies (of 1 total)

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