Thanks for the code, bu i don’t quite understand what the issue is.
Can you please clarify the question?
What does and doesn’t work?
Where is your code found?
Is your code within an action?
Why is it broken into 2 parts which would cause PHP errors?
Why have you copied / pasted source code from the select field type?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users