I have added more data to my comment using hooks. I added a group of radio buttons so users can select and choose one of radio buttons. Everything works perfectly fine but the newly added radio buttons do not show up when you're already logged in.. they only show up and work when you are not logged in. Logged in users only see the comment box.
How to show the newly added field alongside with the comment box to logged in user?
this is what I added to my functions.php
function add_comment_fields($fields) {
if(is_user_logged_in()) {
$fields['age'] = '<p class="comment-form-age"><label for="age">' . __( 'Age' ) . '</label>' .
'<input id="age" name="age" type="text" size="30"' . $aria_req . ' /></p>';
return $fields;
}
}
add_filter('comment_form_default_fields','add_comment_fields');
function add_comment_meta_values($comment_id) {
if(isset($_POST['age'])) {
$age = wp_filter_nohtml_kses($_POST['age']);
add_comment_meta($comment_id, 'age', $age, false);
}
}
add_action ('comment_post', 'add_comment_meta_values', 1);