WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 {

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.

Thank you.

share|improve this question
up vote 0 down vote accepted

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

if ( get_user_meta('phone') !='' ) { 
echo "Your phone is not set";

else {
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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