[wp-hackers] Filter search query before execution
Milan Dinić
liste at srpski.biz
Mon Oct 18 17:53:35 UTC 2010
Since my issues would be titled same, I'll post it here.
I want to format search term in usage specific for Serbian language.There is
issue when posts are written in Cyrillic script and user searches with
Latin, they don't get any result although there is probably result with that
term transliterated in Cyrillic.
So what we need is to transliterate that search term and that search for it
too. I used code from plugin Search Everything to get to version of possible
solution: one that use straight PHP transliteration (PHP transliteration
from Latin to Cyrillic can have bad results, depending on term), and Google
Transliteration. (see
http://sr.forums.wordpress.org/topic/cirilicna-pretraga-u-wordpressu#post-994
)
Both solutions work but with some big problems:
1) search also includes drafts, revisions, and probably private posts
2) if custom menus are used, they are completely broken (menus contain
search results)
3) searching for a phrase (like "my search") doesn't work; I don't get how
this actually works in WordPress
So any suggestion at how this code can be improved or even usage of any
other hook?
Thanks in advance
2010/9/16 Tom Jenkins <tom at thejenkinsweb.com>
> So why not just highjack the post method through javascript, make your
> changes, then forward the post method onto wordpress?
>
>
> Tom
>
>
> On Wed, Sep 15, 2010 at 5:12 PM, Ryan Bilesky <rbilesky at gmail.com> wrote:
>
> > It doesn't look like that filter is what i need. I want to capture the
> > search query before anything is done with it to change it, not while its
> > doing some queries to find results for the search.
> > On Wed, Sep 15, 2010 at 1:22 PM, scribu <scribu at gmail.com> wrote:
> >
> > > On Wed, Sep 15, 2010 at 9:28 PM, Ryan Bilesky <rbilesky at gmail.com>
> > wrote:
> > >
> > > > Best i can find this is a really new filter, only since 3.0 and I
> can't
> > > > seem
> > > > to figure out how to get it working. I setup a simple example on my
> > demo
> > > > install of WP. I had my filter function return Hello World and
> > searched
> > > > something else that didn't yield any results. Hello world should
> give
> > > the
> > > > the initial hello world post, i get nothing.
> > > >
> > >
> > > You should look at what the filter expects first, before returning
> > > something
> > > else:
> > >
> > > function my_posts_search( $sql ) {
> > > var_dump( $sql );
> > > return $sql;
> > > }
> > >
> > > add_filter( 'posts_search', 'my_posts_search' );
> > >
> > >
> > > --
> > > http://scribu.net
> > > _______________________________________________
> > > wp-hackers mailing list
> > > wp-hackers at lists.automattic.com
> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list