#19074 closed defect (bug) (invalid)
'transition_post_status' is executed before 'save_post'
| Reported by: | M66B | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 3.2.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
The action 'transition_post_status' is incorrectly executed before 'save_post' for custom post types
Change History (7)
#2
@
15 years ago
- Cc 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.
#3
@
15 years ago
- Milestone Awaiting Review
- Resolution → invalid
- Status new → 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.
#4
@
15 years ago
- Resolution invalid
- Status closed → 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.
#5
@
15 years ago
- Resolution → invalid
- Status reopened → 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.
#7
@
10 years ago
I hate to necro an old ticket, but I've been struggling for 3 days to discern why wp_transition_post_status wasn't working on new posts, and finally found this ticket, which points to the answer.
Because wp_transition_post_status fires early, we don't have access to a new post's post->ID, which means we can't grab metadata or a legitimate post object. We also don't actually know if the post was saved at all.
I understand that you can't modify this method, but the documentation should be updated in order to reflect the deficiencies of this hook. It's basically useless on anything but saved posts.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.