Searching Posts Programmatically in a WordPress Plugin

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.