I've got this loop where I need to grab a custom post type, get a taxonom, then for each term in taxonomy I need to output all posts. They are all output in a gallery, where taxonomy term is the title, posts are the items in the gallery (for that I use http://bit.ly/1jCf2Wj). I have something like this:


        global $post;
        $post_type = 'people';
        $taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
        $tax = $taxonomies[0];
        $terms = get_terms( $tax );

        //make the query
        $people_args = array( 'post_type' => $post_type);  
        $loop = new WP_Query( $people_args ); //look for people posts
        $termsLength = count($terms);// count terms in the taxonomy, returns correct number

        //for each people post
        while ( $loop->have_posts() ) : $loop->the_post();

        //for each term in the taxonomy
        for ($x = 0; $x <= $termsLength-1; $x++) {
          //this is all posts looped by terms length - 1 

          //if the post has got the name (department name) in $tax (departments group)
          if( has_term( $terms[$x]->name, $tax ) ) {

            echo '<div style="display:block;clear:both; margin-left:0px; z-index:9999; ">'. $terms[$x]->name .'</div>';

            // echo '<div style="display:block;clear:both; margin-left:990px; z-index:9999;">'.$wp_query->post_count.'</div>';
            $name = $terms[$x]->name; // dept name
            $title = get_the_title($post->ID); // the post title
            $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' ); // the post thumb
            $url = $thumb['0']; // url to thumb
            echo '<li data-pile="'. $name .'">';
            echo '<a href="#">';
            echo '<span class="tp-info"><span>'.$title.'</span><span class="profile-smaller">'. get_post_meta($post->ID, 'position', true).'</span></span>';
            echo '<img src="'. $url .'" />';
            echo '</a></li> ';


        rewind_posts(); wp_reset_query();


What happens is I get the the results of the query, but not all posts are there. If I publish more posts than x, then one of taxonomy terms (departments) are not showing up. Another taxonomy term shows only one post.

Where am I making a mistake?

1 Answer 1


Turns out setting explicity posts per page did if for me.

  • Did you set posts_per_page to -1?
    – windyjonas
    Apr 9, 2015 at 11:33
  • Not the right thing to do, but I've set it to 9999999. Apr 10, 2015 at 13:11

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.