[wp-hackers] Modify Search Functionality
Denis de Bernardy
denis at semiologic.com
Wed Jun 22 00:22:02 GMT 2005
Hi Bill,
You might want to fetch some sample code over here:
http://www.semiologic.com/projects/search-reloaded/
D.
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of
> Bill Smith
> Sent: Tuesday, June 21, 2005 9:27 PM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Modify Search Functionality
>
>
> Nikolay Bachiyski wrote:
>
> > ml_wordpress at copperleaf.org wrote:
> > > I want to be able to add some columns in a table I've
> added with a
> > > plugin to the standard search. How would I go about doing this? Is
> > there
> > > any kind of filter that I can use to modify the query string?
> > >
> > > Bill
> >
> > Let us talk in code first:
> >
> > function modify_search_string($query) {
> > $query->set('s', 'baba');
> > }
> >
> > add_action('parse_query', 'modify_search_string');
> >
> > $query is a reference to the WP_Query object whose parse_query is
> > called. For details about what can you do with $query see
> the WP_Query
> > code in classes.php (nope, I didn't find WP_Query docs in
> the codex).
>
> Let me go into some more detail here. I have an additional table that
> has the post id as one of the columns and and another column
> that is a
> text column.
> The query I want to generate would be something like
>
> SELECT DISTINCT wp_post.* FROM wp_post
> LEFT JOIN mytable ON wp_post.ID = mytable.ID
> WHERE ((wp_post.post_title LIKE '%word%')
> OR (wp_post.post_content LIKE '%word%')
> OR (mytable.description LIKE '%word%'))
> AND (post_status = "publish")
> GROUP BY p.ID
> ORDER BY post_date DESC LIMIT 0, 10
>
>
> Where it gets nasty for me is I need to 1) add the left join. That
> doesn't seem too bad since there is the posts_join filter. However
> adding the additional or piece for mytable seems to be a
> challenge. Here
> is the "where" string that I get passed in the posts_where
> filter. With
> multiple words in the search list, it seems to get even
> nastier. I would
> need to insert my piece in there inside the parens.
>
> AND 0=1 AND (((post_title LIKE '%word%') OR (post_content LIKE
> '%word%')) OR (post_title LIKE '%word%') OR (post_content LIKE
> '%word%')) AND post_date_gmt <= '2005-06-21 19:12:59' AND
> (post_status =
> "publish")
>
> Is there a cleaner way than this?
>
> TIA,
> Bill
> _______________________________________________
> 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