[wp-hackers] Filter search query before execution

scribu mail at scribu.net
Mon Oct 18 20:22:56 UTC 2010


On Mon, Oct 18, 2010 at 8:53 PM, Milan Dinić <liste at srpski.biz> wrote:

> 2) if custom menus are used, they are completely broken (menus contain
> search results)
>

Instead of:

function md_lattocyr_search_filter($search) {
  global $wp_query

  // rest of code here
}

add_filter('posts_search', 'md_lattocyr_search_filter');

write:

function md_lattocyr_search_filter($search, $wp_query) {
  if ( $GLOBALS['wp_query'] !== $wp_query )
    return $search;

  // rest of code here
}

add_filter('posts_search', 'md_lattocyr_search_filter', 10, 2);


More information about the wp-hackers mailing list