Is this your exact code? If it is then you have an extra opening php tag that appears before your first endif. There is no closing php tag on the code that precedes this. I’m not sure if this would cause it, but it would cause something to go wrong.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users