1

I have a function using the filter preprocess_comment and want to use the update_comment_meta( $comment['comment_ID'], 'post_id', $post_id );. However, the array in preprocess_comment doesn't have comment_ID.

In looking at filters, I cannot find a different one to use for this function.

The function writes the comment to an external forum. This part of the function works but stops at the update_comment_meta due to an error "duplicate" comment. In looking at the database, the comment_post_ID is written to the database and not the comment_ID.

In trying to understand this challenge, the comment_ID is not in the array. This makes since since it is "preprocess" of the comments and an ID would not be available. Is this correct?

Therefore how can I write to the _commentmetatable so that the comment_ID is written and not the comment_Post_ID?

I've looked through hooks for comments but don't see anything that I can hook into so that comments are written to an external forum and allow the comment meta data to be updated.

Does anyone have any suggestions on the direction to take?

1
  • Why do you want the comment_ID "written" but no the comment_post_ID? That doesn't make sense.
    – s_ha_dum
    Commented Dec 27, 2015 at 19:08

1 Answer 1

3

You won't get a comment ID until the post is is inserted into the database. Before that point, the ID doesn't exist. You have to use a hook that fires after that event...

1735            /**
1736             * Fires immediately after a comment is inserted into the database.
1737             *
1738             * @since 1.2.0
1739             *
1740             * @param int        $comment_ID       The comment ID.
1741             * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
1742             */
1743            do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'] );

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.