Query post for today, if no post get the previous one

I think you should make a recursion function that will call itself if there’s no posts found passing new date to query for..

function getDatePosts( $date, $query_args ) {

$query_args['date_query'] = array(
    'year' => date( 'Y', $date ),
    'mounth' => date( 'm', $date ),
    'day' => date( 'd', $date )
);

$query = new WP_Query( $query_args );

if( ! $query->have_posts() ) {
    $date = $date - ( 60 * 60 * 24 );
    $query = getDatePosts( $date, $query_args );
}

return $query;

}

And use it in your template:

$query = getDatePosts( time(), array( 'post_type' => 'post', 'posts_per_page' => 5 ) );
while( $query->have_posts() ) : $query->the_post();
 // output
endwhile;

Not tested, but should work.

error code: 523