Title: Duplicate comments
Last modified: August 30, 2016

---

# Duplicate comments

 *  [johransz](https://wordpress.org/support/users/johransz/)
 * (@johransz)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/duplicate-comments-3/)
 * I was working on the function of duplicate comments. I have the fallow code in
   the comment.php file of wp-inlcude but its not working:
 *     ```
       **
        * Validates whether this comment is allowed to be made.
        *
        * @since 2.0.0
        *
        * @global wpdb $wpdb WordPress database abstraction object.
        *
        * @param array $commentdata Contains information on the comment
        * @return mixed Signifies the approval status (0|1|'spam')
        */
       function wp_allow_comment( $commentdata ) {
       	global $wpdb;
   
       if(is_page(2999)){
   
       } else {
   
       	// Simple duplicate check
       	// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
       	$dupe = $wpdb->prepare(
       		"SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ",
       		wp_unslash( $commentdata['comment_post_ID'] ),
       		wp_unslash( $commentdata['comment_parent'] ),
       		wp_unslash( $commentdata['comment_author'] )
       	);
       	if ( $commentdata['comment_author_email'] ) {
       		$dupe .= $wpdb->prepare(
       			"OR comment_author_email = %s ",
       			wp_unslash( $commentdata['comment_author_email'] )
       		);
       	}
       	$dupe .= $wpdb->prepare(
       		") AND comment_content = %s LIMIT 1",
       		wp_unslash( $commentdata['comment_content'] )
       	);
       	if ( $wpdb->get_var( $dupe ) ) {
       		/**
       		 * Fires immediately after a duplicate comment is detected.
       		 *
       		 * @since 3.0.0
       		 *
       		 * @param array $commentdata Comment data.
       		 */
       		do_action( 'comment_duplicate_trigger', $commentdata );
       		if ( defined( 'DOING_AJAX' ) ) {
       			die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
       		}
       		wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 );
       	}
       }
       ```
   
 * If its page id 2999 then duplicate is allowd else not.
 * Even if i change the if statement to the fallow it doesn’t work
 *     ```
       /**
        * Validates whether this comment is allowed to be made.
        *
        * @since 2.0.0
        *
        * @global wpdb $wpdb WordPress database abstraction object.
        *
        * @param array $commentdata Contains information on the comment
        * @return mixed Signifies the approval status (0|1|'spam')
        */
   
       function wp_allow_comment( $commentdata ) {
       	global $wpdb;
   
       $string = "home";
                 $container = $post->post_title;
                   if(strstr($container,$string)) {
   
       } else {
       ```
   

The topic ‘Duplicate comments’ is closed to new replies.

## Tags

 * [comment](https://wordpress.org/support/topic-tag/comment/)
 * [duplicate](https://wordpress.org/support/topic-tag/duplicate/)
 * [page_id](https://wordpress.org/support/topic-tag/page_id/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [johransz](https://wordpress.org/support/users/johransz/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/duplicate-comments-3/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
