How to programmatically fetch posts matching a search query in WordPress?

Posted by Alan Bellows on Stack Overflow See other posts from Stack Overflow or by Alan Bellows
Published on 2012-04-01T01:28:15Z Indexed on 2012/04/01 5:29 UTC
Read the original article Hit count: 189

In my plugin code I would like to perform a WP_Query (or similar) which returns all posts matching a given query string, as if the user typed that same string into the WordPress search form. Perhaps I'm just being dense, but I cannot seem to find a way to do so. I would expect to have a special parameter for WP_Query, such as matching, but I see no evidence of one.

I'll start going through the WordPress codebase to see how it's done internally, and I'll post the answer here if I find it. I just thought someone might happen to know offhand.

© Stack Overflow or respective owner

Related posts about php

Related posts about Wordpress