I'm now using WP Posts to Posts plugin in wordpress.
And now I made some links between posts and posts, users and users, or posts and users.
And in all three cases above, I want to do more with the p2p plugin.
For example, I may fetch the p2p_id first:
$users = get_users( array(
'connected_type' => 'multiple_authors',
'connected_items' => $post
) );
foreach($users as $user) {
$p2p_id = $user->p2p_id;
// ********** ATTENTION *********
// Here, I got the p2p_id of the p2p object
// In a general purpose, I want to get the
// from and to object from the p2p_id
}
So, how can I get the from and to object via the p2p_id? I've found over the documentation, but seemed no effective ways.
No other answers. So I finally found the answer myself from the source code:
File: /wp-content/plugins/posts-to-posts/vender/scribu/lib-posts-to-posts/api.php
Notice that there is a function: p2p_get_connection($p2p_id)
Then we call that function with a known p2p_id
, an stdClass Object is returned, like the below:
object(stdClass)#2509 (4) {
["p2p_id"]=>
string(1) "8"
["p2p_from"]=>
string(2) "84"
["p2p_to"]=>
string(1) "2"
["p2p_type"]=>
string(10) "my_post_to_user"
}
Now that we can get the p2p_from
id and p2p_to
id, and we know it is a post or an user. We can construct the object.
So the finally solution may look like:
$conn = p2p_get_connection($this->p2p_id);
$from = get_post(intval($conn->p2p_from));
$to = new WP_User(intval($conn->p2p_to));
Still seemed not found in the documentation, hope it helps.