I have a WP_Query that divides 2 Posts types by date but the functionality is not there. Currently it outputs the dates and posts on the same level like..


What I would like is to wrap each date and its associated posts inside a div, as well as split the two post types for each date into two columns.

enter image description here


I managed to split the posts up by date and wrap them in separate divs, now I just need to figure out how to divide the two CPTs into separate columns under each date

Updated Query

$day_check = '';
$index = new WP_Query( array(
   'post_type' => array('cpt1', 'cpt2'),
   'posts_per_page' =>12));
while ( $index->have_posts() ) : $index->the_post();
   $day = get_the_date('j');
   if ($day != $day_check) {
      if ($day_check != '') {
         echo '</div></div>'; // close the divs
      echo '<div class="day"><div class="date">' . get_the_date() . '</div><div class="posts">';
   <li class="post"><?php the_title(); ?></li>
<?php $day_check = $day; endwhile; ?>
<?php if ( $index->have_posts() ) :?>                                         
<?php endif; ?>
  • I'm not sure about it. Have you checked the posts_groupby thing? Commented Dec 25, 2013 at 7:43
  • updated with new query
    – SBM
    Commented Dec 25, 2013 at 9:31

1 Answer 1


The post_type isn't really a meta query - therefore, both of these post_types would at least 1 category added/queried in order to get the filter invoked - using plain SQL is still a last resort.

add_filter( 'posts_groupby', 'my_posts_groupby' );

function my_posts_groupby($groupby) {
   global $wpdb;
   $groupby = "{$wpdb->posts}.post_date";
   return $groupby;

According to your example (I'd guess one can pass it like that as well):

$args = array(
   'posts_per_page' => 10, 
   'orderby' => 'date',
   'groupby' => 'date', /* unsure about the parameter, should be easy to find out */
   'post_type' => array('type1', 'type2')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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