admin管理员组文章数量:1130222
I have a custom post type called Projects
that includes an ACF field named team_members
which uses User
as a field type and returns a User Array. I want to filter the post type listing so that the current logged-in user sees only records that contain their data in the team_members
field.
I am trying to use this query, but it returns all the records:
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 global
global $current_user;
//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 == 'projects') {
$current_user_id = $current_user->ID;
$query->set( 'meta_query', array(
array(
'key' => 'team_members',
'value' => $current_user_id,
'compare' => "LIKE"
),
));
}
}
Here is my custom field team_members
:
And here is the example of a post from custom post type Projects
:
How can I query only by the ACF field team_members
that has the exact user ID as the current user in the post?
本文标签:
版权声明:本文标题:How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current us 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736722194a1949531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论