Add a
Question
This snippet does exactly what I need, except for the fact that it shows what type of user (Administrator, Editor, Author, Subscriber, Contributor) is posting the comment.
I wanted to adapt it to insert my own fields.
add_filter( 'comment_form_field_comment', function( $field ) {
global $wp_roles;
$user = wp_get_current_user();
$select = '<p><label for="roleselect">Your role:</label>
<select name="prefix_role" id="roleselect">
<option value="">Select a role</option>';
foreach ( $wp_roles->roles as $key => $role )
$select .= sprintf(
'<option value="%1$s" %2$s>%3$s</option>',
esc_attr( $key ),
( in_array( $key, $user->roles) ? 'selected' : '' ),
esc_html( $role['name'] )
);
$select .= '</select></p>';
return $select . $field;
});
add_action( 'comment_post', function( $comment_ID ) {
$roles = new WP_Roles;
$role_keys = array_keys( $roles->roles );
if ( isset ( $_POST['prefix_role'] ) and in_array( $_POST['prefix_role'], $role_keys ) )
update_comment_meta( $comment_ID, 'prefix_role', $_POST['prefix_role'] );
});
add_filter( 'comment_text', function( $text, $comment ) {
if ( $role = get_comment_meta( $comment->comment_ID, 'prefix_role', TRUE ) )
$text = "Role: $role<br> $text";
return $text;
}, 10, 2 );
Sorry for the amateurism. I am new to the area. What I want to do is add options for the commenter to specify how long it took to be served at a particular location. Example:
How long did it take you to be attended?
0
custom-field, dropdown
3 years
2019-10-29T18:33:46-05:00
2019-10-29T18:33:46-05:00 0 Answers
78 views
0
Leave an answer