When you write a post an ID of 0 is assigned. This doesn’t change until it is saved, so the ID needs to be grabbed after a save (or autosave) has occured.
WordPress Post ID
8th Aug 2009
When you write a post an ID of 0 is assigned. This doesn’t change until it is saved, so the ID needs to be grabbed after a save (or autosave) has occured.