To log a user in you really only need the user’s ID
. Based on your info you should be able to obtain it from the username
field.
// Get User object
$user = get_user_by( 'login', $username );
// Clear any auth cookies
wp_clear_auth_cookie();
// Log the user in
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID );
On a non-login page you could probably refresh right after;
header("Refresh:0");
exit();
Now that the hard part is out of the way, it comes down to where you’re getting your username
from.
Most people don’t store username
/password
in plaintext on post_metadata
. But even then, and you’re making a whole loop query for login data, you’re still going to have to settle on logging in a single user. So the whole $data['result'][]=
doesn’t make a lot of sense.