Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to create a hidden field in the user comment form storing the logged in users info (already created a custom field at registration) so I can pass it to the comments section to display on the website.

How can I create a hidden field and display it in the recorded comment section, or is there a better way of 'stamping' a piece of user meta data in a comment? Thanks.

share|improve this question
    
I don't understand. Comments are already associated with a user ID for logged in users. You ought to be able to pull anything you want using that ID. –  s_ha_dum Jan 17 '13 at 16:58
    
Maybe I'm making this too complicated...OK how do I display a piece of user meta data in a user comment? Thanks for your help. –  user1684099 Jan 17 '13 at 19:30
    
Edit your question to reflect that change of focus and I will put together a solution. –  s_ha_dum Jan 17 '13 at 21:27
add comment

1 Answer

If you look in your theme's comments.php file, you should see a call to wp_list_comments. If that has a callback parameter-- something like this array( 'callback' => 'twentyeleven_comment' )-- then your theme has its own comment display function. Find that function. It is probably in function.php but no promises. If not, you need to make one. That function controls the comment display. Inside that function do something like this:

  $user = get_user_by('login',$comment->comment_author);
  if ($user) {
    $umeta = get_user_meta($user->ID);
    echo '################################';
    var_dump($umeta);
    echo '################################';
  }

And you should have what you need-- just a matter of formatting it.

http://codex.wordpress.org/Function_Reference/get_user_by

http://codex.wordpress.org/Function_Reference/get_user_meta

share|improve this answer
    
Thanks for that but a bit lost...I found wp_list_comments parameter but no function in my functions.php (I use Woothemes Canvas theme) so unsure how to create the full function. Your code to go inside the function - in the echo part I presume that's where you specify the exact user meta? Sorry I'm fairly new to this. –  user1684099 Jan 18 '13 at 9:30
    
I actually got it from this code:global $post; $id = get_comment(get_comment_ID())->user_id; ?> <?php $field='industry'; echo the_author_meta($field, $id ); ?> Thanks for your help though. –  user1684099 Jan 18 '13 at 13:15
add comment

Your Answer

 
discard

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.