$wp_query->the_post() fonksiyonun sonucunuda direk ekrana basıyor ise the_post methodunu bulup direk o methotdan return edebilirsin. fakat orası öyle olmak zorunda diyorsan şöyle birşey kullanabilirsin.
function the_post() {
global $wp_query;
ob_start();
$wp_query->the_post();
$out = ob_get_contents();
ob_end_clean();
return $out;
}
$the_post = the_post();
echo $the_post;