each_connected in wp_user_query with Scribu’s Posts to Posts Plugin – Alternative method?

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

Read More
$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?

Update:

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.

Related posts

1 comment

Comments are closed.