Title: Posts 2 Posts within a loop
Last modified: August 21, 2016

---

# Posts 2 Posts within a loop

 *  Resolved [jduffell](https://wordpress.org/support/users/jduffell/)
 * (@jduffell)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/)
 * Hi there, I’m running a loop to display classes, using the post type ‘class’ 
   is it possible within this query to then add run the posts 2 posts connected 
   type ‘Class – Teacher’ within this? when I add the following code, it doesn’t
   output despite there being connections.
 *     ```
       <?php query_posts('post_type=class&showposts=-1&orderby=title&order=asc'); ?>
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <?php the_title(); ?>
   
       <?php
       $connected = new WP_Query( array(
       'connected_type' => 'Class - Teacher',
       'connected_items' => get_queried_object(),
       ) );
       if ( $connected->have_posts() ) : ?>
       ?>
       <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
       <?php the_title(); ?>
       <?php endwhile; ?>
       <?php
       wp_reset_postdata();
       endif;
       ?>
   
       <?php endwhile; ?>
       <?php else : ?>
       <?php endif; ?>
       ```
   
 * The basic idea is to list night classes, along with the teachers who will run
   the class, just not sure where to go from here. Help much appreciated, thanks
 * [http://wordpress.org/plugins/posts-to-posts/](http://wordpress.org/plugins/posts-to-posts/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Nathan Pinno](https://wordpress.org/support/users/whiteeagle1985/)
 * (@whiteeagle1985)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441839)
 * I’m interested in this as well, because this could let me show chapters of a 
   story at my fan fiction archive without needing to wait for a fan fiction plugin!
 *  Thread Starter [jduffell](https://wordpress.org/support/users/jduffell/)
 * (@jduffell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441971)
 * [@whiteeagle1985](https://wordpress.org/support/users/whiteeagle1985/) I’ve been
   having a tinker but I’m struggling to achieve the desired result. Have you had
   much luck ?
 * ^JD
 *  [Nathan Pinno](https://wordpress.org/support/users/whiteeagle1985/)
 * (@whiteeagle1985)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441972)
 * I’ve found another way which is less complicated than using this plugin.
 *  Thread Starter [jduffell](https://wordpress.org/support/users/jduffell/)
 * (@jduffell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441973)
 * [@whiteeagle1985](https://wordpress.org/support/users/whiteeagle1985/) any tips?
 *  [Nathan Pinno](https://wordpress.org/support/users/whiteeagle1985/)
 * (@whiteeagle1985)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441974)
 * CustomPress (from WPMU DEV) and Organize Series can work well, even if they cost
   money to fully implement. 😉
 *  Thread Starter [jduffell](https://wordpress.org/support/users/jduffell/)
 * (@jduffell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441975)
 * cheers, will have a gander, really liked this plugin just couldn’t get my head
   around this 🙁
 *  Thread Starter [jduffell](https://wordpress.org/support/users/jduffell/)
 * (@jduffell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441976)
 * I feel like an idiot, within the code, I’d used $postt, my damn fat fingers.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Posts 2 Posts within a loop’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [jduffell](https://wordpress.org/support/users/jduffell/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/posts-2-posts-within-a-loop/#post-4441976)
 * Status: resolved