php - Get the from and to object from p2p_id in WordPress - WP Posts to Posts Plugin -
i'm using wp posts posts plugin in wordpress.
and made links between posts , posts, users , users, or posts , users.
and in 3 cases above, want more p2p plugin.
for example, may fetch p2p_id first:
$users = get_users( array( 'connected_type' => 'multiple_authors', 'connected_items' => $post ) ); foreach($users $user) { $p2p_id = $user->p2p_id; // ********** attention ********* // here, got p2p_id of p2p object // in general purpose, want // , object p2p_id }
so, how can , object via p2p_id? i've found on documentation, seemed no effective ways.
no other answers. found answer myself source code:
file: /wp-content/plugins/posts-to-posts/vender/scribu/lib-posts-to-posts/api.php
notice there function: p2p_get_connection($p2p_id)
then call function known p2p_id
, stdclass object returned, 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 can p2p_from
id , p2p_to
id, , know post or user. can construct object.
so solution may 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 documentation, hope helps.
Comments
Post a Comment