Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to display a list which shows one post (and information about the person posting) from each custom taxonomy term.

The code I am using is as follows, but it is instead printing out EVERY single post.

I could really use some help on this.

My code is as follows:

                <?php $post_type = 'guestblogs';

                // Get all the taxonomies for this post type
                $taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );

                foreach( $taxonomies as $taxonomy ) : 

                    // Gets every "category" (term) in this taxonomy to get the respective posts
                    $terms = get_terms( $taxonomy );

                    foreach( $terms as $term ) : 

                        $posts = new WP_Query( "post_type=$post_type&taxonomy=$taxonomy&term=$term->slug&posts_per_page=1" );

                        if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>

                           <div class="meet-bloggers-box clearfix">

                                <img class="alignleft" src="<?php the_field('profile_image','user_'.get_the_author_meta('ID')); ?>" style="height:210px; width:140px;" />           

                                <h5><?php the_terms($post->ID, 'guestbloggers'); ?></h5>

                                <div class="meta blogs">

                                    A blog by <?php the_author_meta(  'display_name', $author->ID ); ?>.

                                </div>

                                <p><?php the_author_meta( 'user_description', $author->ID ); ?></p> 

                                <hr />

                                <h5 class="latest-post"><?php the_author_firstname(); ?>'s Latest Post: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>

                                <p><?php echo wp_trim_words( get_the_excerpt(), 45, '...</p><div class="read-more alignright"><a class="paragraph-about internal-list-read-more" href="'. get_permalink($post->ID) . '">...continue reading this article</a>' ); ?> or view <?php the_author_firstname(); ?>'s entire archive in <?php the_terms($post->ID, 'guestbloggers', '', '', ''); ?>.</div>

                           </div><!-- end of .meet-bloggers-box -->

                       <?php endwhile; endif;

                    endforeach;

                endforeach; ?>
share|improve this question
    
What do you mean by "every" single post precisely? Your code seems ok. –  Rarst Oct 8 '12 at 18:31
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.