Posts 2 Posts
Connected posts during the loop- empty array (2 posts)

  1. stayfq
    Posted 4 years ago #

    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:

    			$args = array(
    				'posts_per_page' => 1,
    				'category_name' => 'featured',
    				'order' => 'desc',
    			$my_query = new WP_Query( $args); ?>
    			<?php if( $my_query->have_posts() ) : ?>
    				// 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>
    		// Display connected pages
    		echo '<p>Related pages:</p>';
    		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>
    				<?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:

    		// Find connected pages
    		$connected = p2p_type( 'bands_to_shows' )->get_connected( $post->ID );
    		// Display connected pages
    		echo '<p>Related pages:</p>';
    		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.


  2. stayfq
    Posted 4 years ago #

    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"

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic