不,不正确-get_user_meta()
返回基于$user_id
您提供的参数。您可以将其与get_current_user_id()
检查用户是否已登录,如果已登录,则获取post meta。E、 g.这样:
$curr_user_id = get_current_user_id();
// the value is 0 if the user isn\'t logged-in
if ( $curr_user_id != 0 ) {
// we know now the user is logged-in, so we can use his/her ID to get the user meta
$um_value = get_user_meta( $curr_user_id, \'your-key\', true );
// now we check if the value is correct
if ( ! empty( $um_value ) && $um_value == \'your-value\' ) {
// if so we can output something
echo \'user meta has the value\';
}
}