2015-08-25 22 views
0

我現在在wordpress中使用WP Posts to Posts插件。在WordPress中獲取和反對p2p_id - WP發佈到帖子插件

現在我在帖子和帖子,用戶和用戶,或帖子和用戶之間建立了一些鏈接。

而在上述所有三種情況下,我想用p2p插件做更多。

例如,我可以先取p2p_id:

$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 

} 

所以,我怎麼能得到從並通過p2p_id反對?我發現了文檔,但似乎沒有有效的方法。

回答

0

沒有其他答案。所以,我終於找到了自己的答案從源代碼:

文件:/wp-content/plugins/posts-to-posts/vender/scribu/lib-posts-to-posts/api.php

注意,有一個函數:p2p_get_connection($p2p_id)

然後我們調用該函數與已知p2p_id,則返回一個stdClass的對象,像下面的:

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" 
} 

現在,我們可以得到p2p_from ID和p2p_to ID,我們知道這是一個後或用戶。我們可以構造這個對象。

所以最終的解決方案可能看起來像:

$conn = p2p_get_connection($this->p2p_id); 
$from = get_post(intval($conn->p2p_from)); 
$to = new WP_User(intval($conn->p2p_to)); 

不過文檔中似乎沒有找到,希望它幫助。

相關問題