Leave a Reply

3 comments

  1. WordPress >=3.3

    There is a caveat with the proposed solution: a meta_key which value is false will give false negatives.

    To ask WordPress if a meta_key is set, even if the value is false, use metadata_exists:

    if ( metadata_exists( 'user', $user_id, $meta_key ) ) {
    
       ...
    
    }
    
  2. (TESTED) If you put true as the last argument, according to documentation, it will return the value of the metadata field. Which means you have to put false as last argument.

    $havemeta = get_user_meta($userID, 'test', false);
    

    Then, as said in the other answer, you can check it

    if ($havemeta)
        echo $havemeta;
    } else {
        echo "No";
    }