I'm using wordpress to implement a very simple blogging system on my already existing website. I've now come across a problem with inserting comments.
I'm using wp_insert_comment to add a new comment for a specific post like below which works just fine.
$comment_post_ID = (int) $_POST['comment_post_ID'];
$comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;
$comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null;
$comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null;
$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
$comment_type = 'comment';
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
$comment_id = wp_insert_comment( $commentdata );
The problem appears when I try to check for duplicate comments. I do this by getting all of the comments for the post and then comparing the new comment with the old ones. So basically I add the following before the w_insert_comment function.
$comments = get_comments("post_id=$comment_post_ID");
code here to compare these comments to the new one.
I've narrowed it down to the get_comments function. If I don't include it everything works fine. If I do include it the insertion of the comment doesn't happen. Any ideas why?
Any help would be much appreciated.