Title: [Plugin: Posts 2 Posts] Connected posts during the loop- empty array
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Connected posts during the loop- empty array

 *  [stayfq](https://wordpress.org/support/users/stayfq/)
 * (@stayfq)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connected-posts-during-the-loop-empty-array/)
 * I am trying to get connected posts in a page. I have this connection set up:
 *     ```
       p2p_register_connection_type( array(
       		'name' => 'bands_to_shows',
       		'from' => 'band',
       		'to' => 'show',
       	) );
       ```
   
 * And here is the code I am trying to use to display:
 *     ```
       <?php
       			$args = array(
       				'post_type'=>'show',
       				'posts_per_page' => 1,
       				'category_name' => 'featured',
       				'order' => 'desc',
       			);
   
       			$my_query = new WP_Query( $args); ?>
   
       			<?php if( $my_query->have_posts() ) : ?>
       							<?php
       				// Find connected pages (for all posts)
       				p2p_type( 'bands_to_shows' )->each_connected( $my_query );
       				?>
       				<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
   
       				<div id="post-<?php echo $post->ID; ?>" class=" featured post-<?php echo $post->ID; ?> show post">
   
       						<?php the_post_thumbnail('shea-med'); ?>
   
       						<h3><a class="post title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
   
       						<span class="date"><?php echo get_field('show_date'); ?></span>
   
       						<?php if($post->post_excerpt)  : the_excerpt(); endif; ?>
       						<p class="excerpt">Click to listen to tracks and check out the band pages</p>
   
       <?php
       		// Display connected pages
       		echo '<p>Related pages:</p>';
       		var_dump($post->connected);
       		p2p_list_posts( $post->connected );
       	?>
   
       						<div class="meta">
       							<span class="doors">Doors at: <?php echo get_field('doors_at'); ?></span>
       							<span class="cover">Cover: <?php echo get_field('cost'); ?></span>
       							<div class="social_media">
       								<span class="fb_like"><?php sfc_like_button(); ?></span>
       								<span class="tweet"><?php echo tweetbutton(); ?></span>
       							</div>
       						</div>
   
       					</div>
   
       				<?php endwhile; ?>
       				<?php wp_reset_postdata(); ?>
       			<?php endif; ?>
       ```
   
 * When I use var_dump I get back an empty array.
 * Also, when I use var_dump on the this method:
 *     ```
       <?php
       		// Find connected pages
       		$connected = p2p_type( 'bands_to_shows' )->get_connected( $post->ID );
   
       		// Display connected pages
       		echo '<p>Related pages:</p>';
       		var_dump($connected);
       		p2p_list_posts( $connected );
       	?>
       ```
   
 * It says that the post_type = post.
 * Any ideas what I am doing wrong? No errors are thrown, just have no results.
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [stayfq](https://wordpress.org/support/users/stayfq/)
 * (@stayfq)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connected-posts-during-the-loop-empty-array/#post-2536724)
 * Just wanted to clarify- when I use ‘var_dump($wp_query->get(‘post_type’));’
 * it returns “shows” (the correct post type”
 * when I use var dump($connected) it shows post_type as being “post”

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Posts 2 Posts] Connected posts during the loop- empty array’
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
 * 1 participant
 * Last reply from: [stayfq](https://wordpress.org/support/users/stayfq/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connected-posts-during-the-loop-empty-array/#post-2536724)
 * Status: not resolved