Title: [Plugin: Posts 2 Posts] 2 connected posts inside each other
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] 2 connected posts inside each other

 *  [winningsem](https://wordpress.org/support/users/winningsem/)
 * (@winningsem)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-2-connected-posts-inside-each-other/)
 * How can I loop 2 connected data inside each other
 * for example I have a a community page that has builders connected to it. then
   I have something called Home Design connected to the builders. now in the community
   page i want to display all the connected builders with all their connected home
   designs I tried the following but it gave an error:
 *  <h1>Builders Working at <?php the_title()?></h1>
 *  <?php
    // Find connected pages $connected = p2p_type( ‘communities_to_builders’)-
   >get_connected( get_queried_object_id() );
 * // Display connected pages
    if ( $connected->have_posts() ) : ?> <?php while (
   $connected->have_posts() ) : $connected->the_post(); ?>
    -  <?php the_title()?>
 * <?php endwhile; ?>
 * <?php
    // Prevent weirdness wp_reset_postdata();
 * endif;
    ?>
 *  <h1>Home Designs at <?php the_title()?> By Builder</h1>
 *  <?php
    // Find connected pages $connected = p2p_type( ‘communities_to_builders’)-
   >get_connected( get_queried_object_id() );
 * // Display connected pages
    if ( $connected->have_posts() ) : ?> <?php while (
   $connected->have_posts() ) : $connected->the_post(); ?>
 *  <div>Builder Name: <?php the_title()?> | With ID:<?php the_id(); ?></div>
 *  <div>Home Design: </div>
    <?php
 *  // Find connected pages
    $connected2 = p2p_type( ‘builders_to_home_design’ )-
   >get_connected(get_queried_object_id());
 *  // Display connected pages
    if ( $connected2->have_posts() ) : ?> <?php while(
   $connected2->have_posts() ) : $connected2->the_post(); ?>
 *  <?php endwhile; ?>
 *  <?php
    // Prevent weirdness wp_reset_postdata();
 *  endif;
    ?>
 * <?php endwhile; ?>
 * <?php
    // Prevent weirdness wp_reset_postdata();
 * endif;
    ?>
 * and here is the error i get
 * Fatal error: Call to a member function get_connected() on a non-object in /home/…/
   single-communities.php on line 202
 * [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)

 *  Thread Starter [winningsem](https://wordpress.org/support/users/winningsem/)
 * (@winningsem)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-2-connected-posts-inside-each-other/#post-2376928)
 * Code Looks better here :): [http://pastebin.com/SccCm4yQ](http://pastebin.com/SccCm4yQ)
 *  Thread Starter [winningsem](https://wordpress.org/support/users/winningsem/)
 * (@winningsem)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-2-connected-posts-inside-each-other/#post-2376930)
 * just in case you need this
    the code in function.php
 *     ```
       /////////////////////////
   
       function my_connection_types() {
           if ( !function_exists( 'p2p_register_connection_type' ) )
               return;
   
           p2p_register_connection_type( array(
       		'id' => 'communities_to_builders',
               'from' => 'builders',
               'to' => 'communities'
           ) );
       }
       add_action( 'init', 'my_connection_types', 100 );
   
       ///////////////////////////////
   
       /////////////////////////
   
       function my_builders_to_home_design() {
           if ( !function_exists( 'p2p_register_connection_type' ) )
               return;
   
           p2p_register_connection_type( array(
       		'id' => 'builders_to_home_design',
               'from' => 'builders',
               'to' => 'home-design'
           ) );
       }
       add_action( 'init', 'my_builders_to_home_design', 100 );
   
       ///////////////////////////////
       ```
   

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

The topic ‘[Plugin: Posts 2 Posts] 2 connected posts inside each other’ 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
 * 1 participant
 * Last reply from: [winningsem](https://wordpress.org/support/users/winningsem/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-2-connected-posts-inside-each-other/#post-2376930)
 * Status: not resolved