Skip to content

Instantly share code, notes, and snippets.

@mbijon
Created February 18, 2013 18:48
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbijon/4979627 to your computer and use it in GitHub Desktop.
Save mbijon/4979627 to your computer and use it in GitHub Desktop.
WordPress posts_search filter example, for Tom Barrett on WP-Hackers list 2013-02-18
function tcb_filter_search( $term ) {
if ( is_search() )
$search = "(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
return $search;
}
add_filter( 'posts_search', 'tcb_filter_search', null, 2 );
@lordspace
Copy link

Why are you not escaping the term?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment