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.
Return Return
(string) 'Yes' if post contains $text (otherwise 'No').
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'; }