Created
June 28, 2020 08:29
-
-
Save elhardoum/1b18b89287465e7a63dcb274b8b15290 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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