0

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.

3
  • 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, 2013 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. Jan 17, 2013 at 19:30
  • Edit your question to reflect that change of focus and I will put together a solution.
    – s_ha_dum
    Jan 17, 2013 at 21:27

1 Answer 1

0

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

2
  • 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. Jan 18, 2013 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. Jan 18, 2013 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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