Child_of not displaying all children posts.. via get_posts

I have put together this loop to display all children posts of the desired cat, but i am not getting any of the posts from one of the children cats..
Not sure if i am using the best method to accomplish what I am trying to do..

 <?php
        $posts = array();
         $categories = get_categories('child_of=5');
         foreach($categories as $category) {
           $args=array(
            'post_per_page' => 5,
            'orderby' => 'post_date',
            'numberposts' => 45,
            'category__in' => array($category->term_id)             
           );
         $posts = $posts + get_posts($args);
        } // Close your foreach here
             shuffle($posts);
              if ($posts) {
                foreach($posts as $post) {
                  setup_postdata($post);
                   ?>
                    <div <?php post_class('boxy');?>><div  class="soc-label" ></div>

                  <?php 
                      if ( has_post_thumbnail()) {
                      $full_image_url =    wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
                      echo '<a href="' . $full_image_url[0] . '" rel="lightbox" title="' . the_title_attribute('echo=0') . '" >';
                      the_post_thumbnail('thumbnail');
                      echo '</a>';
                    }
                   ?>

                    <?php the_content(''); ?>
                    </div>


        <?php } 
           } 

        ?>

I am using the results in a tiled mosaic of sorts with Isotope, and I am shuffling the results, thats also a must..
Any guidance would be appreciated I have spend the last couple weeks getting as far as I am now.

Related posts

Leave a Reply

2 comments

  1. Your foreach is way wrong. Try combining the category ids in an array, then running one query only to get the posts you want.

    Edit: read your comments. Try use using an array function like array_merge instead of the + to combine the resulting post arrays. See if that helps.

  2. I Was able to get it working using array_merge()..
    Here is the code.. still might have a couple code errors but its working.

        <?php
            $posts = array();
             $categories = get_categories('child_of=4');
             foreach($categories as $category) {
               $args=array(         
                'orderby' => 'post_date',
                'numberposts' => 40,
                'category__in' => array($category->term_id)             
               );
             $posts = array_merge($posts,get_posts($args));
            } // Close your foreach here
                 shuffle($posts);
                  if ($posts) {
                    foreach($posts as $post) {
                      setup_postdata($post);
                       ?>
                        <div <?php post_class('boxy');?>><div class="soc-label" ></div>
    
                      <?php 
                          if ( has_post_thumbnail()) {
                          $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
                          echo '<a href="' . $full_image_url[0] . '" rel="lightbox" title="' . the_title_attribute('echo=0') . '" >';
                          the_post_thumbnail('thumbnail');
                          echo '</a>';
                        }
                       ?>
    
                        <?php the_content(''); ?>
                        </div>
    
    
            <?php } 
               } 
    
            ?>