Title: [Plugin: Posts 2 Posts] Get connected posts&#039; thumbnails?
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Get connected posts' thumbnails?

 *  Resolved [protohominid](https://wordpress.org/support/users/protohominid/)
 * (@protohominid)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/)
 * Seems like this would’ve been asked before, so if it was, sorry for the repeat.
   My searches didn’t return anything…
    I have a connection working great, with 
   connected posts being rendered as a list on my page. What I’d like to do is include
   those posts’ thumbnails along with the normal result of the title and link. Is
   this possible? Thanks again for your excellent work!
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512596)
 * Just use `the_post_thumbnail()`, like on any other loop. Obviously, this is not
   possible using `p2p_list_posts()` alone.
 *  Thread Starter [protohominid](https://wordpress.org/support/users/protohominid/)
 * (@protohominid)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512627)
 * Sounds like if I can’t do it within the “p2p_list_posts” function it’s not possible.
   Thanks for the quick reply, though.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512629)
 * > if I can’t do it within the “p2p_list_posts” function it’s not possible.
 * I don’t understand how you reached that conclusion. In the wiki, you have an 
   example of using The Loop instead of p2p_list_posts():
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage](https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage)
 * Just replace this:
 *     ```
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       ```
   
 * with this:
 *     ```
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); the_post_thumbnail(); ?></a></li>
       ```
   
 *  Thread Starter [protohominid](https://wordpress.org/support/users/protohominid/)
 * (@protohominid)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512632)
 * Awesome, that’s exactly what I was looking for. I didn’t realize you could use
   the p2p plugin that way.
 * Thanks again!
 *  [Derek Perkins](https://wordpress.org/support/users/ploobers/)
 * (@ploobers)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512824)
 * I’m doing that in my loop, but the information isn’t cached like it is for other
   queries. As soon as I introduce P2P syntax into the query args, every single 
   call to the_thumbnail() gives me two database queries.
 * SELECT * FROM sr_posts WHERE ID = 2437 LIMIT 1
    SELECT post_id, meta_key, meta_value
   FROM sr_postmeta WHERE post_id IN (2437)
 * Is there some way to prefill the cache with one database call, or do I need to
   build my own SQL query directly?
 *  [Derek Perkins](https://wordpress.org/support/users/ploobers/)
 * (@ploobers)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512825)
 * If it helps, here’s my code for the loop. If I comment out just ‘the_post_thumbnail’,
   my queries for the page are reduced by 129 (43 posts returned by this query x
   3)
 *     ```
       $items = new WP_Query( array( 'connected_type'=>'player_club', 'connected_items'=>'2363', 'posts_per_page'=>'-1' ) );
   
       	// Display connected pages
       	if ( $items->have_posts() ) :
       	while ( $items->have_posts() ) : $items->the_post();
       		the_post_thumbnail( );
       		the_permalink( );
       	endwhile;
       	endif;
       	// Prevent weirdness
       	wp_reset_postdata();
       ```
   
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512826)
 * The code that does the caching seems to work only for the main $wp_query object:
   [http://core.trac.wordpress.org/changeset/17883](http://core.trac.wordpress.org/changeset/17883)
 * Hopefully, this will be fixed soon: [http://core.trac.wordpress.org/ticket/19949](http://core.trac.wordpress.org/ticket/19949)
 *  [Derek Perkins](https://wordpress.org/support/users/ploobers/)
 * (@ploobers)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512827)
 * Thanks for looking into that and for submitting a patch so quickly. I think I’ll
   change my core code for the time being until 3.4 is released.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘[Plugin: Posts 2 Posts] Get connected posts' thumbnails?’ 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/)

 * 8 replies
 * 3 participants
 * Last reply from: [Derek Perkins](https://wordpress.org/support/users/ploobers/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-get-connected-posts-thumbnails/#post-2512827)
 * Status: resolved