admin管理员组文章数量:1332969
I do work on filter posts by current user, but in my dropdown list, i can get only all users list, but I need to see only the current user
function getСurrentUserForFilter(){
$res = '';
$user_query = new WP_User_Query(array('number'=>999));
$users = $user_query->get_results();
foreach($users as $user){
echo'<option value="'.$user->ID.'">'.$user->user_email.'</option>';
}
return $res;
}
what am I doing wrong?
I do work on filter posts by current user, but in my dropdown list, i can get only all users list, but I need to see only the current user
function getСurrentUserForFilter(){
$res = '';
$user_query = new WP_User_Query(array('number'=>999));
$users = $user_query->get_results();
foreach($users as $user){
echo'<option value="'.$user->ID.'">'.$user->user_email.'</option>';
}
return $res;
}
what am I doing wrong?
Share Improve this question asked Jun 16, 2020 at 12:06 LerryLerry 1111 gold badge2 silver badges10 bronze badges1 Answer
Reset to default 2If you just want to write a single <option>
for the current user, you can get the user object from wp_get_current_user() - you don't need a WP_User_Query at all:
function getСurrentUserForFilter() {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
echo '<option value="'.$user->ID.'">'.esc_html($user->user_email).'</option>';
}
}
本文标签: filtersGet current user data
版权声明:本文标题:filters - Get current user data 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742344875a2457324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论