Title: [Plugin: Posts 2 Posts] Querying Efficiency Question
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Querying Efficiency Question

 *  Resolved [letusrise](https://wordpress.org/support/users/letusrise/)
 * (@letusrise)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-querying-efficiency-question/)
 * Good day! I have a question regarding about multiple connections between multiple
   post types upon querying them.
 * Lets say, I have:
    Post Type: A Post Type: B Post Type: C
 * and my Posts-to-Posts Relationship Connection:
    #1 – Post Type A to Post Type
   B #2 – Post Type A to Post Type C #3 – Post Type B to Post Type C
 * My idea for querying their relationship is this.
 * FIRST QUERY: (stored an array of ids to a variable)
    I first use the #2 connection
   and query all post that is related to Post Type A to Post Type C, (1 post of 
   Post Type A and get multiple post of Post Type C related to A). I would have 
   multiple Post Type C post and store them in array for the next query to be used.
 * Nested Query:
    SECOND QUERY: After that, I use connection #1 to get posts of 
   Post Type B that is connected to Post Type A (1 post of Post Type A or single
   Post Type A).
 * THIRD QUERY: (used the variable from the result of the FIRST QUERY.)
    This is
   nested query with the previous query, getting a relationship from Post Type B
   and C using the #3 connection. Then, check if the array with stored in the first
   query is related to the results from third query. (Using If statements) – Finally,
   displaying the results.
 * Is this the right one for getting their relationship?
    If this is not an efficient
   idea, can you share your alternative way of doing it?
 * Thanks and God Bless! 🙂
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-querying-efficiency-question/#post-2702200)
 * Have you seen [each_connected()](https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop)?
   especially the “Further nesting” section.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Posts 2 Posts] Querying Efficiency Question’ 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/)

 * 1 reply
 * 2 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-querying-efficiency-question/#post-2702200)
 * Status: resolved