0

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?

1 Answer 1

2

If 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>';
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.