WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Get connected posts' thumbnails? (9 posts)

  1. protohominid
    Member
    Posted 2 years ago #

    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/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

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

  3. protohominid
    Member
    Posted 2 years ago #

    Sounds like if I can't do it within the "p2p_list_posts" function it's not possible. Thanks for the quick reply, though.

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    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

    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>
  5. protohominid
    Member
    Posted 2 years ago #

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

    Thanks again!

  6. Derek Perkins
    Member
    Posted 2 years ago #

    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?

  7. Derek Perkins
    Member
    Posted 2 years ago #

    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();
  8. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    The code that does the caching seems to work only for the main $wp_query object: http://core.trac.wordpress.org/changeset/17883

    Hopefully, this will be fixed soon: http://core.trac.wordpress.org/ticket/19949

  9. Derek Perkins
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic