Title: [Plugin: Posts 2 Posts] Query Connected Posts
Last modified: August 19, 2016

---

# [Plugin: Posts 2 Posts] Query Connected Posts

 *  [stinkyleaf](https://wordpress.org/support/users/stinkyleaf/)
 * (@stinkyleaf)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-query-connected-posts/)
 * So we have an article we would like to connect to some media posts. How do we
   in our template query if the post has a connection then display the content we
   are defining in the following code. For example, if post has a connection (using
   posts to posts) then query the specific content of that post which we already
   have in place in the below code.
 *     ```
       <div class="secendary-wrap">
                       <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
       					$temp = $wp_query;
       					$wp_query= null;
       					$wp_query = new WP_Query();
       					$wp_query->query("paged=$page&cat=10");
       					if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
       					while ($wp_query->have_posts()) : $wp_query->the_post();?>
                           <div style="margin-right:8px;">
                    		<!--Run Timthumb Image Resize Script -> post-img to 312x126px - Zoom Crop of 0 - Quality 75% -->
       					<?php if( get_post_meta($post->ID, "post-img", true) ): ?>
                           <div class="frontpage-widget-img">
                           <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php bloginfo('template_directory'); ?>/js/timthumb.php?src=<?php echo get_post_meta($post->ID, "post-img", $single = true); ?>&w=312&zc=2&q=75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a></div>
                           <?php else: ?>
                           <?php endif; ?>
                           <!--Title, Author, Dat/Time -->
       				    <?php include (TEMPLATEPATH . '/inc/title_author_date_time.php' ); ?>
                           <!--Truncate excerpt number = word count -->
                           <p class="excerpt-widget"><?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,40); ?></p>
                        	<!--FOOTER LINK NAV -->
       					<?php include (TEMPLATEPATH . '/inc/widget_footer_nav.php' ); ?>
       					</div><!--Close Metro-->
       				 <?php endwhile ?>
       					<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
       					<?php $wp_query = null; $wp_query = $temp; ?>
                       </div><!--Close seconday wrap 1-->
       				<?php wp_reset_query(); ?>
       ```
   

The topic ‘[Plugin: Posts 2 Posts] Query Connected Posts’ 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/)

 * 0 replies
 * 1 participant
 * Last reply from: [stinkyleaf](https://wordpress.org/support/users/stinkyleaf/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-query-connected-posts/)
 * Status: not resolved