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

  • Resolved protohominid


    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!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author scribu


    Just use the_post_thumbnail(), like on any other loop. Obviously, this is not possible using p2p_list_posts() alone.

    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


    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():

    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>

    Awesome, that’s exactly what I was looking for. I didn’t realize you could use the p2p plugin that way.

    Thanks again!

    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?

    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( );
    	// Prevent weirdness
    Plugin Author scribu


    The code that does the caching seems to work only for the main $wp_query object:

    Hopefully, this will be fixed soon:

    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.