WC_Tracker::post_contains_text
Search a specific post for text content.
Метод класса: WC_Tracker{}
Хуков нет.
Возвращает
Строку. 'Yes' if post contains $text (otherwise 'No').
Использование
$result = WC_Tracker::post_contains_text( $post_id, $text );
- $post_id(int) (обязательный)
- The id of the post to search.
- $text(строка) (обязательный)
- The text to search for.
Код WC_Tracker::post_contains_text() WC Tracker::post contains text WC 10.3.4
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';
}