0

If I navigate to Posts -> All Posts in a Wordpress install, there's a Search Box in the upper right hand corner. Entering terms in this box and clicking the Search Posts button will perform a search.

Does Wordpress provide a hook, function, or other API that would allow me to programmatically perform the same (or a similar) search? i.e. I pass in a string as terms and get back a PHP array of results without needing to write any SQL myself.

If not, does anyone here know where in the Wordpress core code the above search happens? (so I cam mimic the behavior as best as possible)

Thank you!

1

Per comments above from mmm

Try this

$posts = get_posts(["s" => "string to search"]); 

Also, Covering the get_posts API is a bit beyond a single StackExchange answer, but if you want to dive deep you'll find more informations in the codex.

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.