WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. stayfq
    Member
    Posted 2 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:

    <?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/

  2. stayfq
    Member
    Posted 2 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

About this Topic