How to check if a custom user profile field is empty

i have this code to limit the comments per user.

<!-- #only one comment -->
<?php global $current_user,$post;
$usercomment = get_comments(array('author_email' => $current_user->user_email, 'post_id' => $post->ID));
if($usercomment) {
    echo "Thank you!";
}
else {
    comment_form();
}
 ?>

How can edit this code to also check if a custom user profile field [phone] is empty? If is empty display a message else display the comment form.

Read More

Thank you.

Related posts

Leave a Reply

2 comments

  1. You can check the user meta for the key you want:

    if ( get_user_meta('phone') !='' ) { 
    echo "Your phone is not set";
    }
    
    else {
    comment_form();
    }
    
  2. get_the_author_meta( 'customfield' ) should give you the information that you can use in your conditional. Assuming customfield would be replaced by phone or whatever your custom field is named.