title: Wordpress order posts by post type
body: <p>I am trying to create a system which fetches post from 2 post types and i want to display the posts order by their post type. I am trying to first show the posts from one post type and then another post type but the query i used mixes it all. Can any one suggest a good solution for this. Here is my code.</p>
  
  <pre><code>    $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
   $args = array(
  
       'post_type' =&gt; array('review','directory'),
       'orderby' =&gt; 'name',
       'order' =&gt; 'ASC',
       'posts_per_page'  =&gt; '4',
       'paged'          =&gt; $paged ,
       'tax_query' =&gt; array( array(
          'taxonomy' =&gt; 'Reviews',
          'field' =&gt; 'id',
          'terms' =&gt; $cat_id
      ), ),
       );
  
   query_posts($args);
          if (have_posts()) :
         while (have_posts()) : the_post();
        $product_terms = wp_get_post_terms(get_the_ID(), 'Reviews', array("fields" =&gt; "all", "order" =&gt; "DESC"));
        $postype=get_post_type( get_the_ID() );
        if($postype=='review')
        {
       ?&gt;   
  
          &lt;div class="review-post"&gt;
            &lt;a href="http://&lt;?php the_permalink(); ?&gt;" target="_blank"&gt;&lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt;&lt;/a&gt;
            &lt;div class="review-cat-new"&gt;
              &lt;?php echo get_the_term_list( $post-&gt;ID, 'Reviews', 'Category: ', ', ', '' ); ?&gt;
            &lt;/div&gt;
  
            &lt;?php
            if(get_field('see_it'))
                $seeit_text= get_field('see_it');
           if(get_field('skip_it'))
                $skipit_text= get_field('skip_it');
           ?&gt;
            &lt;div class="see-skip"&gt;
              &lt;p class="see-it"&gt;&lt;span&gt;See it:&lt;/span&gt;
                  &lt;?php echo $seeit_text; ?&gt;
              &lt;/p&gt;
              &lt;p class="skip-it"&gt;&lt;span&gt;Skip it:&lt;/span&gt;
                  &lt;?php echo $skipit_text;  ?&gt;
              &lt;/p&gt;
            &lt;/div&gt;
            &lt;?php echo custom_field_excerpt(); ?&gt;
          &lt;/div&gt;
            &lt;?php }
            else
            {
                ?&gt;
                  &lt;div class="review-post"&gt;
            &lt;a href="h&lt;?php the_permalink(); ?&gt;" target="_blank"&gt;&lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt;&lt;/a&gt;
            &lt;div class="review-cat-new"&gt;
              &lt;?php echo get_the_term_list( get_the_ID(), 'Reviews', 'Category: ', ', ', '' ); ?&gt;
            &lt;/div&gt;
  
  
            &lt;?php echo the_field('enter_content_direc'); ?&gt;
            &lt;?php
            if(get_field('enter_textdirec'))
                $text= get_field('enter_textdirec');
           if(get_field('enter_linkdirec'))
                $textlink= get_field('enter_linkdirec');
           ?&gt;
            &lt;div class="see-skip"&gt;
              &lt;p class="see-it direc"&gt;&lt;span&gt;&lt;a  target="_blank" style="color:#5D6D71; text-transform: lowercase;" href="&lt;?php echo $textlink;?&gt;"&gt;&lt;?php echo $textlink;?&gt;  &lt;/a&gt;&lt;/span&gt;
  
              &lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
            &lt;?php }
            endwhile;
                    echo '&lt;div class="paging"&gt;';
                   wp_pagenavi();
                   echo '&lt;/div&gt;';
                  endif;
  </code></pre>
  
  <p>So is there a way so that i can first show the posts form reviews and then directory? </p>