2017-06-16 53 views
0

我有自定義帖子類型umowy哪一個與用戶有關係。關係是由編輯用戶通過acf添加的。我想要的是?我想列在儀表板自定義帖子類型umowy所有與用戶登錄有關係的帖子。我有這樣的代碼。它的顯示帖子僅供用戶登錄哪一個是作者。有人有想法嗎?WordPress的過濾儀表板自定義帖子由用戶與關係

add_action('pre_get_posts', 'filter_posts_list'); 
function filter_posts_list($query) 
{ 
    //$pagenow holds the name of the current page being viewed 
    global $pagenow, $typenow; 

    //$current_user uses the get_currentuserinfo() method to get the currently logged in user's data 
    global $current_user; 
    get_currentuserinfo(); 

     //Shouldn't happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php 
     if(!current_user_can('administrator') && current_user_can('edit_posts') && ('edit.php' == $pagenow) && $typenow == 'umowy') 
    { 
     //global $query's set() method for setting the author as the current user's id 
     $query->set('author', $current_user->ID); 
     } 
} 

回答

0

我找到答案:

if(!current_user_can('administrator') && !current_user_can('obsluga') && ('edit.php' == $pagenow) && $typenow == 'umowy'){ 

    $key = 'użytkownik_sklep'; 
    $single = true; 
    $shopIds = get_user_meta($current_user->data->ID, $key, $single); 

    $meta_query = array(
     array(
      'key' => 'umowa_do_sklepu', 
      'value' => $shopIds[0], 
      'compare' => 'LIKE' 
     ) 
    ); 
    $query->set('meta_key', 'umowa_do_sklepu'); 
    $query->set('meta_query', $meta_query); 

} 
相關問題