ap_find_duplicate_post( string $content, string $post_type = 'question', integer|false $question_id = false )

Description #

Find duplicate post by content.

Parameters #

  • $content
    string (Required) Post content.
  • $post_type
    string (Optional) Post type. Default value: 'question'
  • $question_id
    integer | false (Optional) Question ID. Default value: false

Changelog #

VersionDescription
4.1.0Removed option check. Removed ap_sanitize_description_field sanitization.
3.0.0Introduced.

Source #

File: includes/functions.php

function ap_find_duplicate_post( $content, $post_type = 'question', $question_id = false ) {
	global $wpdb;

	// Return if content is empty. But blank content will be checked.
	if ( empty( $content ) ) {
		return false;
	}

	$question_q = false !== $question_id ? $wpdb->prepare( ' AND post_parent= %d', $question_id ) : '';

	$var = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_content = %s AND post_type = %s {$question_q} LIMIT 1", $content, $post_type ) ); // @codingStandardsIgnoreLine

	if ( $var > 0 ) {
		return $var;
	}

	return false;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment