First off – sorry, I accidentally marked this as solved and apparently there’s no way to unmark it? Still not solved for me, apologies!
When I put the first 3 lines I posted inside of my function, it turns the whole function into an unending loop and the custom fields don’t load on my page at all.
Let me know if I can make myself clearer – I know this problem is a bit confusing.