1

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.

Thank you.

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();
}
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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