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

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.

  • 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 '14 at 22:41
  • Do you have any other ideas? – JLewkovich Feb 2 '14 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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