I found the problem. It was a function which I wrote. and one I had disable, trouble shooting. commenting it out to check what was causing the issue. But the problem was the php ending tag before my comment. It was causing the function to execute, not as a function but directly. And for some reason it was only affecting the admin. I'm guess as it was terminating the previous function what was adding the custom fields to the admin section.
How it was functioning correctly in the template at all is beyond me. It shouldn't have.