4

I am making a custom theme and have edited comments.php, but I'm unable to get the comments to save as a reply to another comment. I have succeeded in showing the comment parent id to show as a hidden value in the source code, but it doesn't save it accordingly in the database (instead, it always saves the comment_parent as 0). Also, the commenter IP address isn't saved either for some reason (comment_author_IP appears as "::1"). Here's the code I have so far:

    <?php
    if ( post_password_required() )
        return;
?>

    <div id="comments" class="comments-area">

    <?php // You can start editing here -- including this comment!

    $fields = array(
    'author'               => '<p class="comment-form-author"><label for="author">' . __( 'Name', 'domainreference' ) . '</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', 'domainreference' ) . '</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>'
    );

    $defaults = array(
    'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
    'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p><p class="comment-form-math"><label for="math">' . __( 'five plus two', 'domainreference' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="math" name="math" type="text" value="' . esc_attr( $commenter['math'] ) . '" size="30"' . $aria_req . ' /></p></p><input type=\'hidden\' name=\'comment_post_ID\' value=\'\' id=\'comment_post_ID\' /><input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.$comment_parent.'\' />',
    'must_log_in'          => '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>',
    'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>',
    'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published. Required fields are marked *' ) . ( $req ? $required_text : '' ) . '</p>',
    'comment_notes_after'  => '',
    'id_submit'            => 'submit',
    'title_reply'          => __( 'Leave a Reply' ),
    'title_reply_to'       => __( 'Leave a Reply to %s' ),
    'comment_form_title'       => __( 'Leave a Reply', 'Leave a Reply to %s' ),
    'cancel_reply_link'    => __( 'Cancel reply' ),
    'label_submit'         => __( 'Post Comment' )
    );

    comment_form($defaults);
    ?>

</div><!-- #comments .comments-area -->
3
  • One problem solved thanks to William: The IP anomaly, '::1' is the IPv6 equivalent to 127.0.0.1 localhost, my IP address since I have WordPress installed locally.
    – Pamela
    Commented Mar 12, 2013 at 14:15
  • Having the same issue... Did you solve this?
    – benedict_w
    Commented Feb 11, 2014 at 12:15
  • @benedict_w, no, I did not. Please let me know if you do.
    – Pamela
    Commented Feb 11, 2014 at 16:18

1 Answer 1

1

If your IP problem is solved that's great did you try the option in word press

setting->discussion->Enable threaded (nested) comments ?

Might solve your DB problem As well if works.

4
  • Thanks. Actually, I tried this, but it did not work.
    – Pamela
    Commented Jun 5, 2013 at 1:35
  • can you share the source url ?
    – Cid Ubaid
    Commented Jun 5, 2013 at 5:07
  • In case if it helps you - its very helpful article about nested comments in detailed - bavotasan.com/2009/…
    – Cid Ubaid
    Commented Jun 5, 2013 at 5:10
  • Thanks for the article. The source URL is still confined to localhost.
    – Pamela
    Commented Jun 9, 2013 at 12:52

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.