WC_Tracker::post_contains_text()public staticWC 1.0

Search a specific post for text content.

Method of the class: WC_Tracker{}

No Hooks.

Return

String. 'Yes' if post contains $text (otherwise 'No').

Usage

$result = WC_Tracker::post_contains_text( $post_id, $text );
$post_id(int) (required)
The id of the post to search.
$text(string) (required)
The text to search for.

WC_Tracker::post_contains_text() code WC 8.7.0

public static function post_contains_text( $post_id, $text ) {
	global $wpdb;

	// Search for the text anywhere in the post.
	$wildcarded = "%{$text}%";

	$result = $wpdb->get_var(
		$wpdb->prepare(
			"
			SELECT COUNT( * ) FROM {$wpdb->prefix}posts
			WHERE ID=%d
			AND {$wpdb->prefix}posts.post_content LIKE %s
			",
			array( $post_id, $wildcarded )
		)
	);

	return ( '0' !== $result ) ? 'Yes' : 'No';
}