0

I'm doing a keyword search using wp_query as so:

$wp_query = new WP_Query( 's=' . $_GET['s'] );

It is returning a post that has $_GET['s'] in one of its image URLs, and I don't want this to happen. I'd like to exclude any attachment URL from the search.

Is this possible using the wp_query arguments? Maybe a way to only search the title/body of a post?

1 Answer 1

1

You just need to add post_type argument like this:

$wp_query = new WP_Query( array(
    's'         => $_GET['s'],
    'post_type' => array( 'post', /* add more post types if need be */ ),
) );

Read the codex article about WP_Query class for more information.

2
  • Using the 'post' post_type still doesn't filter out the images that are embedded within the post. Is there anyway to only search text within a post? Not the HTML itself?
    – jlewkovich
    Jan 29, 2014 at 22:41
  • Do you have any other ideas?
    – jlewkovich
    Feb 2, 2014 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.