Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elhardoum/1b18b89287465e7a63dcb274b8b15290 to your computer and use it in GitHub Desktop.
Save elhardoum/1b18b89287465e7a63dcb274b8b15290 to your computer and use it in GitHub Desktop.
<?php
// temporarily disable post_title matching for wp query search
add_filter('posts_where_paged', $disablePostTitleSearch=function( string $sql )
{
return str_replace('.post_title LIKE ', '.post_content LIKE ', $sql);
});
// now query posts
$posts = query_posts([
'numberposts' => -1,
'posts_per_page' => PHP_INT_MAX,
'post_type' => ['post','page'],
's' => 'keyword',
]);
// enable back title search for subsequent calls
remove_filter('posts_where_paged', $disablePostTitleSearch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment