I want to create a WP_Query which functions as the WordPress search. I thought this was just a matter of passing in the following as the args, but that doesn't seem to be working. Can anyone confirm that this is the right approach (and that I need to fix my own bug) or suggest another approach, please? I do want to do this with WP_Query if at all possible, rather than some wrapper function.
Thanks in advance.
S
--- Sweet Interaction Ltd is Registered in England/Wales, no. 6610741 Registered office: 7 Malton Av, Manchester, M21 8AT _______________________________________________ wp-hackers mailing list wp-hack...@lists.automattic.com http://lists.automattic.com/mailman/listinfo/wp-hackers
Are you just trying to modify or override the default WP search? There are a few filters you can use to modify the query fairly extensively. The Search Everything plugin has some nice code that can give you an idea of working with that stuff:
> I want to create a WP_Query which functions as the WordPress search. I > thought this was just a matter of passing in the following as the > args, but that doesn't seem to be working. Can anyone confirm that > this is the right approach (and that I need to fix my own bug) or > suggest another approach, please? I do want to do this with WP_Query > if at all possible, rather than some wrapper function.
On Mon, Apr 13, 2009 at 8:21 PM, SoJ Web <soj...@indiana.edu> wrote:
> Are you just trying to modify or override the default WP search? There are a > few filters you can use to modify the query fairly extensively. The Search > Everything plugin has some nice code that can give you an idea of working > with that stuff:
Thanks for the suggestion. To (attempt to) clarify a little:
Currently I'm creating listings of recent posts in categories for use on various templates by defining a WP_Query thus:
I was hoping for something similar, using WP_Query, which would allow me to return posts as per a WP search but with the results restricted to a particular set of categories. I'm fine with using the WHERE filters on the SQL generated by the WP_Query and so I could do my SQL LIKE stuff here, but I hoped it might be possible to reuse the existing code in WP_Query which manages the WP search results to generate my restricted search results. (Seems like less code duplication.)
I think I get what you're saying: You want to have a number of mini- loops that list posts from certain categories that match some search term? Try something like this:
// query for a given term ("search_term") in some given categories (7 and 8) $search_query = new WP_Query(); $search_posts = $search_query->query('s=search_term&cat=7,8');
// build loop foreach($search_posts as $search_post) { setup_postdata($search_post);
// do stuff
}
And you can put those mini-loops wherever you need them. Is that the sort of thing you were looking for?
-Jeff
On Apr 13, 2009, at 5:40 PM, Simon Wheatley wrote:
> On Mon, Apr 13, 2009 at 8:21 PM, SoJ Web <soj...@indiana.edu> wrote:
>> Are you just trying to modify or override the default WP search? >> There are a >> few filters you can use to modify the query fairly extensively. The >> Search >> Everything plugin has some nice code that can give you an idea of >> working >> with that stuff:
> Thanks for the suggestion. To (attempt to) clarify a little:
> Currently I'm creating listings of recent posts in categories for use > on various templates by defining a WP_Query thus:
> I was hoping for something similar, using WP_Query, which would allow > me to return posts as per a WP search but with the results restricted > to a particular set of categories. I'm fine with using the WHERE > filters on the SQL generated by the WP_Query and so I could do my SQL > LIKE stuff here, but I hoped it might be possible to reuse the > existing code in WP_Query which manages the WP search results to > generate my restricted search results. (Seems like less code > duplication.)
----- Original Message ----- From: "Simon Wheatley" <si...@sweetinteraction.com> To: wp-hack...@lists.automattic.com Sent: Monday, April 13, 2009 5:40:34 PM GMT -05:00 US/Canada Eastern Subject: Re: [wp-hackers] Setting up a WP Query with a search
On Mon, Apr 13, 2009 at 8:21 PM, SoJ Web <soj...@indiana.edu> wrote:
> Are you just trying to modify or override the default WP search? There are a > few filters you can use to modify the query fairly extensively. The Search > Everything plugin has some nice code that can give you an idea of working > with that stuff:
Thanks for the suggestion. To (attempt to) clarify a little:
Currently I'm creating listings of recent posts in categories for use on various templates by defining a WP_Query thus:
I was hoping for something similar, using WP_Query, which would allow me to return posts as per a WP search but with the results restricted to a particular set of categories. I'm fine with using the WHERE filters on the SQL generated by the WP_Query and so I could do my SQL LIKE stuff here, but I hoped it might be possible to reuse the existing code in WP_Query which manages the WP search results to generate my restricted search results. (Seems like less code duplication.)
On Tue, Apr 14, 2009 at 12:23 AM, SoJ Web <soj...@indiana.edu> wrote:
> I think I get what you're saying: You want to have a number of mini-loops > that list posts from certain categories that match some search term? Try > something like this:
> // query for a given term ("search_term") in some given categories (7 and 8) > $search_query = new WP_Query(); > $search_posts = $search_query->query('s=search_term&cat=7,8');
That worked great. Thank you.
S
--- Sweet Interaction Ltd is Registered in England/Wales, no. 6610741 Registered office: 7 Malton Av, Manchester, M21 8AT _______________________________________________ wp-hackers mailing list wp-hack...@lists.automattic.com http://lists.automattic.com/mailman/listinfo/wp-hackers