Not really sure about the issue in general, but this is incorrect right off the bat:
echo the_field
When you use the_field, it outputs to screen so no need to echo. Maybe that’s what the problem is.
Try replacing every instance of echo the_field
and the_field
to simply: get_field()
.
Hope this helps.