Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been using Scribu's Posts to Posts plugin for some time, and it has served me well. I have read the full wiki and issues list, but can't find any definitive answer if there is a clean way to loop through many users while getting each_connected.

According to this wiki entry, the faster way to get connections inside a loop, is to use each_connected, to avoid having a second query inside each and every iteration of the loop. Makes sense, and works great for posts of varying types. But despite the similarities between wp_query and wp_user_query, this kind of thing doesn't work (but would work if we were in a wp_query instead):

$players = new WP_User_Query( array( 'role' => 'subscriber' ) );
p2p_type( 'player_report_to_user' )->each_connected( $players );

If I run this kind of connection inside the foreach($players as $player) ...

$reports = get_posts( array(
    'connected_type' => 'player_report_to_user',
    'connected_items' => $player->ID,
    'suppress_filters' => false,
    'nopaging' => true
) );

It absolutely works, but is very inefficient, as I have over 200 users being processed.

So, the question is: does anyone know of a method for applying each_connected() to a wp_user_query() so that I'm not making hundreds of extra queries?


It seems the answer is "No." according to this: https://github.com/scribu/wp-posts-to-posts/issues/374 - So might there be a way to write the SQL myself? I'm pretty shaky at that.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

No, it isn't possible without modifications to the p2p plugin, as indicated here:


Relevant code is here:


share|improve this answer
lol... spoonfed :) –  GhostToast Jun 17 '13 at 15:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.