WC_Tracker::post_contains_text( integer $post_id, string $text )

Search a specific post for text content.


Description Description


Parameters Parameters

$post_id

(Required) The id of the post to search.

$text

(Required) The text to search for.


Top ↑

Return Return

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


Top ↑

Source Source

File: includes/class-wc-tracker.php

	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';
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.