Title: [Plugin: Posts 2 Posts] Using plugin within another query
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Using plugin within another query

 *  Resolved [snails07](https://wordpress.org/support/users/snails07/)
 * (@snails07)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-plugin-within-another-query/)
 * Not sure if I am on the right track or not but I will explain my problem…
 * I have created the connections between video (custom post type) and director (
   custom post type) and this is working.
    I have a WordPress page template setup
   that is calling (via WP_Query) a list of videos and the information that goes
   with each video. This works fine. Within this query I am trying to get the name
   of the connected director using the_title.
 * The code I have for the connection is (plus the function and add_action code 
   above and below)
 *     ```
       p2p_register_connection_type( array(
       		'name' => 'director_to_portfolio',
       		'from' => 'director',
       		'to' => 'portfolio',
       		'reciprocal' => true
       	) );
       ```
   
 * The code to display the title of the director is this…
    (which is within the 
   WP-Query that is calling the video posts)
 *     ```
       <?php
       // Find connected pages
       $connected = new WP_Query( array(
         'connected_type' => 'director_to_portfolio',
         'nopaging' => true,
       ) );
   
       // Display connected pages
       if ( $connected->have_posts() ) :
       while ( $connected->have_posts() ) : $connected->the_post(); ?>
       	<a>"><?php the_title(); ?></a>
   
       <?php endwhile;
       // Prevent weirdness
       wp_reset_postdata();
       endif;
       ?>
       ```
   
 * This is displaying the title of all standard posts. Not sure what I am doing 
   wrong??
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  [salocined](https://wordpress.org/support/users/salocined/)
 * (@salocined)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-plugin-within-another-query/#post-2659057)
 * Maybe, in your query, you can add
 *     ```
       $connected = new WP_Query( array(
         'post_type' => 'director',
         'connected_type' => 'director_to_portfolio',
         'nopaging' => true,
       ) );
       ```
   
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-plugin-within-another-query/#post-2659103)
 * Passing the post_type won’t help. What you’re missing is the ‘connected_items’
   parameter, which would restrict the results to posts that are connected to a 
   certain post.
 * That said, you should be using each_connected():
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop](https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop)

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

The topic ‘[Plugin: Posts 2 Posts] Using plugin within another query’ 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/)

 * 2 replies
 * 3 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-plugin-within-another-query/#post-2659103)
 * Status: resolved