How to save custom fields on comments?

I have the following code to save a comment from a custom form, via POST:

if (!empty($_POST)) {
    $time = current_time('mysql');

    $data = array(
        'comment_post_ID' => $_POST['comment_post_id'],
        'comment_author' => $_POST['author'],
        'comment_author_email' => $_POST['email'],
        'comment_content' => $_POST['comment_content'],
        'comment_type' => '',
        'comment_parent' => $_POST['comment_parent'],
        'comment_author_IP' => $_POST['author_IP'],
        'comment_date' => $time,
        'comment_approved' => 0
    );

    wp_insert_comment($data);
}

Everything is working fine, but how do I add a custom field to $data? My custom field is already created, and I’m using:

Read More
    update_comment_meta( $_POST['comment_post_id'], 'author_avatar', $_POST['author_avatar'] );

To register the author avatar on the custom field. But when the comment is saved, the field appears to be empty.

Does wp_insert_comment accept custom fields? Any suggestions?

Related posts

Leave a Reply

1 comment