WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a blog using only Wordpress's backend. I have found functions to get latest posts (wp_get_recent_posts) and all the required data I need. I do this by including wp-load so I have access to WP's functions.

However I cannot find anything that allows me to perform a search outside of Wordpress's theming loops as I have for the rest of the data.

I was hoping there was a search function where I can pass it a search query that could be in title, body content or tag name.

Am I missing something blindingly obvious in the documentation, there seems to be a function for everything else I need outside of WP's "loop".

share|improve this question
up vote 1 down vote accepted

You can use get_posts() with a search parameter:

$results = get_posts( array( 's' => 'search term' ) );
share|improve this answer
Works great, thank you very much! – GreenGiant Dec 3 '12 at 15:28
It's also worth adding 'numberposts' => -1 otherwise it falls back to the default of max 5 posts. It doesn't seem to search tags, but good enough – GreenGiant Dec 3 '12 at 15:31
Good shout. You can pass in anything you would pass into WP_Query but the s param has the effect of search all post types unless specified - also worth noting. – sanchothefat Dec 4 '12 at 10:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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