3

I've been searching high and low for this but can't find anything that explains how to add custom fields to only the reply form. I've seen and got working custom fields on the comment form, but when a user clicks reply, I want to have a different set of fields. Better still a different set of fields depending on the reply level.

Here’s what I’m trying to do.

Suppose you have a site which posts a blog entry that you want people to post reviews and comments as a first level comment. I’d add a custom field for the first level comment with the options (radio button or drop down): “Review”, “Comment”. That's easy enough to do and well documented.

Then for 2nd level replies I want people to be post a comment that says whether they agree or disagree with that review and why, or just make a comment, so I want add a field to second level replies that has the options: “Agree”, “Disagree”, “Comment”, but the custom field on the first level comment (with "Reivew", "Comment") should not be displayed. This is what I can't figure out or find any tips on nor can I find any hooks/filters that allow you to access the reply form.

I looked at this question (that seems similar) but couldn't figure out what was done and so can't tell if it's a solution: Customize reply form different to comment form

Any help greatly appreciated.

1
  • Ever get this figured out? I'm trying to do something similar.
    – CragMonkey
    Mar 28, 2018 at 23:56

2 Answers 2

1

By using comment_form( $args, $post_id ) you can add extra field in your comment form like this

$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields =  array(
    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
        '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
    'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
        '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
);

$comments_args = array(
    'fields' =>  $fields
);


comment_form($comments_args);

also Customizing Comments fields

1
  • 1
    @armitrh, thanks for your reply, but that modifies all comments forms -- main comments and replies. I want to modify the main comment and reply forms so they are different. I need each to have their own fields that won't be on the other form.
    – Mohib
    Dec 19, 2014 at 8:11
0

We can even add fields to the comment for using the 'comment_form_default_fields' filter. add this in function. We can add a field as follows:

function add_comment_fields($fields) {

$fields['age'] = '<p class="comment-form-age"><label for="age">' . __( 'Age' ) . '</label>' .
    '<input id="age" name="age" type="text" size="30" /></p>';
return $fields;
}

add_filter('comment_form_default_fields','add_comment_fields');

#respond .comment-form-author label,
#respond .comment-form-email label,
#respond .comment-form-url label,
#respond .comment-form-age label,
#respond .comment-form-comment label {
background: #eee;
-webkit-box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
-moz-box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
box-shadow: 1px 2px 2px rgba(204,204,204,0.8);
color: #555;
display: inline-block;
font-size: 13px;
left: 4px;
min-width: 60px;
padding: 4px 10px;
position: relative;
top: 40px;
z-index: 1;
}

Reference url

Your Answer

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

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