#19074 closed defect (bug) (invalid)
'transition_post_status' is executed before 'save_post'
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Post Types | Version: | 3.2.1 |
| Severity: | normal | Keywords: | |
| Cc: | M66B |
Description
The action 'transition_post_status' is incorrectly executed before 'save_post' for custom post types
Change History (6)
- Cc M66B added
But what is the reason this is done differently for custom post types?
The problem is that 'transition_post_status' is called before the post meta values can be saved, resulting in this problem.
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
It isn't done differently for custom post types. wp_insert_post() is used for pages, posts, custom post types.
You'll need to check your checkbox on transition_post_status in order to have the value ready for those hooks.
- Resolution invalid deleted
- Status changed from closed to reopened
I have tested it again and it is really like this:
Regular post type: save_post, then transition_post_status and another save_post
Custom post types: transition_post_status, then save_post
Maybe wp_insert_post does it the right way, but the fact remains the order is different for custom post types.
You'll need to check your checkbox on transition_post_status in order to have the value ready for those hooks
The checkbox is checked in transition_post_status already, but the problem is that this works for the regular post type, but not for custom post types, because of the order the hooks are called.
- Resolution set to invalid
- Status changed from reopened to closed
Check the post type of the post objects before doing anything.
If your post type supported revisions, you'd see both actions fire twice -- transition then save for the revision, transition then save for the post.

I understand why it may make more sense to fire transition_post_status after save_post (in some situations), but that's not how wp_insert_post() is architected. We can't change it now.