Skip to content

Instantly share code, notes, and snippets.

@dcavins
Created April 17, 2015 19:14
Show Gist options
  • Save dcavins/3787e4e56a7116b61532 to your computer and use it in GitHub Desktop.
Save dcavins/3787e4e56a7116b61532 to your computer and use it in GitHub Desktop.
Modify the search "WHERE" statement in WordPress
add_filter('posts_search', 'what_the_search', $priority = 10, $accepted_args = 2);
function what_the_search( $search, $query ){
if ( $query->is_search ) {
$towrite = PHP_EOL . '$search: ' . print_r( $search, TRUE );
// $search looks like:
// AND (((wp_posts.post_title LIKE '%walking%') OR (wp_posts.post_content LIKE '%walking%'))) AND (wp_posts.post_password = '')
$fp = fopen('what_the_search.txt', 'a');
fwrite($fp, $towrite);
fclose($fp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment