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?

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.

share|improve this question

closed as off-topic by birgire, Pieter Goosen, G. M., Johannes Pille, kaiser Sep 22 at 15:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – birgire, Pieter Goosen, G. M., Johannes Pille, kaiser
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 2 down vote accepted
+50

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

https://github.com/scribu/wp-posts-to-posts/issues/374

Relevant code is here:

https://github.com/scribu/wp-posts-to-posts/blob/master/core/connection-type.php#L374

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

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