Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Setting up a WP Query with a search
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Simon Wheatley  
View profile  
 More options Apr 13, 2:28 pm
From: Simon Wheatley <si...@sweetinteraction.com>
Date: Mon, 13 Apr 2009 19:28:58 +0100
Local: Mon, Apr 13 2009 2:28 pm
Subject: [wp-hackers] Setting up a WP Query with a search
Hi,

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SoJ Web  
View profile  
 More options Apr 13, 3:21 pm
From: SoJ Web <soj...@indiana.edu>
Date: Mon, 13 Apr 2009 15:21:55 -0400
Local: Mon, Apr 13 2009 3:21 pm
Subject: Re: [wp-hackers] Setting up a WP Query with a search
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:

http://wordpress.org/extend/plugins/search-everything/

Not to say it's the best method, depending on what you're doing, but  
it's reasonably straightforward and easy to maintain.

-Jeff

On Apr 13, 2009, at 14:28 PM, Simon Wheatley wrote:

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Wheatley  
View profile  
 More options Apr 13, 5:40 pm
From: Simon Wheatley <si...@sweetinteraction.com>
Date: Mon, 13 Apr 2009 22:40:34 +0100
Local: Mon, Apr 13 2009 5:40 pm
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:

$args = array(
        'post_type' => $post_type,
        'what_to_show' => 'posts',
        'post_status' => 'publish',
        'posts_per_page' => $num_posts,
        'orderby' => 'modified',
        'order' => 'DESC',
        'cat' => $cat_ids,
);
$new_wp_query = new WP_Query( $args );

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 thought it might be as simple as:

$args = array(
        's' => $search_string,
);
$search_wp_query = new WP_Query( $args );

...but that doesn't seem to be working for me. :(

Are you suggesting that I should kick off a WP_Query as per my first
example and then use the WHERE filters to mess with the resultant SQL?

Thanks again.

S

P.S. Search Everything is certainly a nicely coded plugin. :)

---
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SoJ Web  
View profile  
 More options Apr 13, 7:23 pm
From: SoJ Web <soj...@indiana.edu>
Date: Mon, 13 Apr 2009 19:23:50 -0400
Local: Mon, Apr 13 2009 7:23 pm
Subject: Re: [wp-hackers] Setting up a WP Query with a search
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:

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Schinkel  
View profile  
 More options Apr 14, 12:34 am
From: Mike Schinkel <mikeschin...@newclarity.net>
Date: Mon, 13 Apr 2009 23:34:36 -0500 (CDT)
Local: Tues, Apr 14 2009 12:34 am
Subject: Re: [wp-hackers] Setting up a WP Query with a search
Simon:

Though I'm not sure exactly what you are looking for, I *think* that what you want is to use "category__in"

$args = array(
        'post_type' => $post_type,
        'what_to_show' => 'posts',
        'post_status' => 'publish',
        'posts_per_page' => $num_posts,
        'orderby' => 'modified',
        'order' => 'DESC',
        'category__in' => explode(",",$cat_ids),  // Assumes $cat_ids is a comma separated string of category ids.
);
$new_wp_query = new WP_Query( $args );

If this isn't what you need, reply with more details and we'll see what we can do to help.

-Mike Schinkel
Custom Wordpress Plugins
http://mikeschinkel.com/custom-wordpress-plugins

----- 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:

$args = array(
        'post_type' => $post_type,
        'what_to_show' => 'posts',
        'post_status' => 'publish',
        'posts_per_page' => $num_posts,
        'orderby' => 'modified',
        'order' => 'DESC',
        'cat' => $cat_ids,
);
$new_wp_query = new WP_Query( $args );

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 thought it might be as simple as:

$args = array(
        's' => $search_string,
);
$search_wp_query = new WP_Query( $args );

...but that doesn't seem to be working for me. :(

Are you suggesting that I should kick off a WP_Query as per my first
example and then use the WHERE filters to mess with the resultant SQL?

Thanks again.

S

P.S. Search Everything is certainly a nicely coded plugin. :)

---
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
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Wheatley  
View profile  
 More options Apr 14, 2:31 am
From: Simon Wheatley <si...@sweetinteraction.com>
Date: Tue, 14 Apr 2009 07:31:07 +0100
Local: Tues, Apr 14 2009 2:31 am
Subject: Re: [wp-hackers] Setting up a WP Query with a search

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google