Plugin Author
scribu
(@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
(@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():
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>
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( );
endwhile;
endif;
// Prevent weirdness
wp_reset_postdata();
Plugin Author
scribu
(@scribu)
The code that does the caching seems to work only for the main $wp_query object: http://core.trac.ww.wp.xz.cn/changeset/17883
Hopefully, this will be fixed soon: http://core.trac.ww.wp.xz.cn/ticket/19949
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.