admin管理员组文章数量:1125377
I need to get the meta value based on user id. Such as, I have meta_key called event_comments and the meta_value for this will be set to either Yes or No. I need to get that for the current user id. What I am trying is below.
$args = array(
'user_id' => $postedby, // $postedby is the user id
'meta_key' => 'event_comments',
'meta_value' => 'Yes',
);
$getuser = get_users($args);
I need to get the meta value based on user id. Such as, I have meta_key called event_comments and the meta_value for this will be set to either Yes or No. I need to get that for the current user id. What I am trying is below.
$args = array(
'user_id' => $postedby, // $postedby is the user id
'meta_key' => 'event_comments',
'meta_value' => 'Yes',
);
$getuser = get_users($args);
Share
Improve this question
asked Feb 9, 2024 at 16:57
Darth Mikey DDarth Mikey D
931 silver badge9 bronze badges
1
|
1 Answer
Reset to default 2get_users
is for retrieving users, not meta.
To get the user meta of a user where $user_id
is that users ID, you can use get_user_meta
and it should work the same as the other meta functions:
$meta_value = get_user_meta( $user_id, 'the meta key', true );
You can use $user_id = get_current_user_id();
to retrieve the ID of the currently logged in user, make sure to check that the user is logged in first though.
本文标签: Get meta value based on user id
版权声明:本文标题:Get meta value based on user id 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736656747a1946275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_user_meta()
? – Pat J Commented Feb 9, 2024 at 17:08