The context of your code that fails isn’t entirely clear, but it’s failing because get_the_ID()
won’t return a post ID when run on the init
hook, because the main query hasn’t been executed yet.
If you have a look at the Action Reference, wp
is the earliest action where you can access the current query’s data, if your code is operating on the currently viewed post. If your code is operating on a different post, you’ll need to pass that post’s ID along with your other form data.