[wp-trac] [WordPress Trac] #48580: Update status in save_post hooks always true in WordPress 5.0
WordPress Trac
noreply at wordpress.org
Mon Sep 8 22:07:43 UTC 2025
#48580: Update status in save_post hooks always true in WordPress 5.0
-------------------------------+----------------------
Reporter: oxibug | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Posts, Post Types | Version: 5.2.4
Severity: normal | Resolution: invalid
Keywords: | Focuses:
-------------------------------+----------------------
Changes (by SirLouen):
* status: new => closed
* resolution: => invalid
* milestone: Awaiting Review =>
Comment:
This is only meant if you use `wp_insert_post` directly. If you use any of
the two editors, by default WP creates a draft post as soon as you start
creating the post, way before you save it. This is to help with the
heartbeat process and the auto-saving process. It doesn't have anything to
do with Gutenberg specifically (although Gutenberg also benefits from
this, as GB mostly communicates changes via WP API).
If you have to have control over this, you must add posts with
`wp_insert_post` passing an array as the first parameter without an ID.
The first time you call it, `$update` will be false, and it by the end, it
will assign the ID and add the post to the database.
So, is `$update` useless? From the editor, pretty much yes. If you want to
know if it's truly a new, there is a hook called `draft_to_publish` (its
status_to_status, but in this case, the transition from `draft` to
`publish` is what you are specifically looking). Also, you can hook to
`transition_post_status` and check if the `new_status` is `publish` and
the `old_status` is not `publish`. Options there are plenty, but the
`$update` one is not meant for what you thought.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48580#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list