Skip to content

Instantly share code, notes, and snippets.

@campusboy87
Created September 8, 2019 15:31
Show Gist options
  • Select an option

  • Save campusboy87/7b9a2d548e2280fff61583c2983b74dc to your computer and use it in GitHub Desktop.

Select an option

Save campusboy87/7b9a2d548e2280fff61583c2983b74dc to your computer and use it in GitHub Desktop.
Ищет посты, у которых в заголовке содержится указанная строка.
<?php
/**
* Ищет посты, у которых в заголовке содержится указанная строка.
*
* @param string $title
*
* @return array
*/
function get_posts_relevant_title( $title ) {
global $wpdb;
$posts = $wpdb->get_results( $wpdb->prepare( "
SELECT *
FROM $wpdb->posts
WHERE 1=1
AND post_status = 'publish'
AND post_title LIKE %s
LIMIT 0, 10
",
'%' . $wpdb->esc_like( $title ) . '%'
) );
return $posts ? array_map( 'get_post', $posts ) : [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment