[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
- The topic ‘[Plugin: Posts 2 Posts] 2 connected posts inside each other’ is closed to new replies.