Title: [Plugin: Posts 2 Posts] Looping the loop help
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Looping the loop help

 *  Resolved [Griffin](https://wordpress.org/support/users/rgriffinj/)
 * (@rgriffinj)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/)
 * First, let me thank you for your wonderful plugin! You’re helping push the limits
   of WordPress as a CMS.
 * **Here’s my question: **
    1. I have two custom post types: ‘Clients’ and “Placements”.
    2. I’m using your plugin to connect ‘Placements’ to ‘Clients’, which is working
       like a charm.
    3. Clients are divided into three industry groups using the value of a custom field(
       I’m using a custom field instead of a taxonomy for unrelated reasons).
    4. I have a page with three columns, each representing one of the three groups 
       of ‘Clients’. In each column, I need to display all the ‘Placements’ that are
       associated with ‘Clients’ in that industry group.
 * Is this possible using your plugin?
 * Thank you!
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432352)
 * You can pass any additional query vars to WP_Query:
 *     ```
       $my_query = new WP_Query( array(
         'connected_type' => 'YOUR_CONNECTION_TYPE',
         'connected_items' => $YOUR_CLIENT_ID,
         'meta_key' => 'YOUR_META_KEY',
         'meta_value' => 'YOUR_META_VALUE',
       ) );
   
       while ( $my_query->have_posts() ) : $my_query->the_posts();
   
       ...
       ```
   
 * And you do that for each column, only changing the meta_value.
 *  Thread Starter [Griffin](https://wordpress.org/support/users/rgriffinj/)
 * (@rgriffinj)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432382)
 * Thanks for the swift response! I had originally tried exactly what you posted,
   but it wasn’t working. Scanning through my code, however, I found a small typo
   that was causing the error. It’s working great now.
 * Thank you!
 *  Thread Starter [Griffin](https://wordpress.org/support/users/rgriffinj/)
 * (@rgriffinj)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432665)
 * Hi!
    So this is working great now. I still have one issue, however. ‘Placements’
   are now organized into groups based on what ‘Client’ they are associated with,
   so they are ordered chronologically within groups, and then each group is ordered
   chronologically with each other. The problem is that I need to order all placements
   chronologically with one another, independent of what ‘Client’ they are associated
   with. In other words, I need my loop to output just a list of ‘Placements’, instead
   of ‘Placements’ grouped by ‘Client’.
 * Let me know if I need to clarify the question further.
 * And thank you!
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432666)
 * In that case, you don’t need to loop the loop at all.
 * Just pass all the client ids to the ‘connected_items’ parameter as an array:
 *     ```
       $my_query = new WP_Query( array(
         'connected_type' => 'YOUR_CONNECTION_TYPE',
         'connected_items' => wp_list_pluck( $wp_query->posts, 'ID' ),
       ) );
   
       while ( $my_query->have_posts() ) : $my_query->the_posts();
       ```
   
 * (assuming `$wp_query->posts` contains a list of ‘client’ posts)
 *  Thread Starter [Griffin](https://wordpress.org/support/users/rgriffinj/)
 * (@rgriffinj)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432667)
 * Thank you! I’ll give it a try.
 *  Thread Starter [Griffin](https://wordpress.org/support/users/rgriffinj/)
 * (@rgriffinj)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432668)
 * Worked perfectly. Thank you! This plugin is great and you’ve been extremely responsive.
   Do you have a donate button somewhere? I’d love to buy you a beer.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432669)
 * I have a donate button in the sidebar: [http://scribu.net/wordpress/posts-to-posts](http://scribu.net/wordpress/posts-to-posts)

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

The topic ‘[Plugin: Posts 2 Posts] Looping the loop help’ 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: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-looping-the-loop-help/#post-2432669)
 * Status: resolved