WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#19074 closed defect (bug) (invalid)

'transition_post_status' is executed before 'save_post'

Reported by: M66B Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

The action 'transition_post_status' is incorrectly executed before 'save_post' for custom post types

Change History (6)

comment:1 @nacin4 years ago

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.

comment:2 @M66B4 years ago

  • 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.

comment:3 @nacin4 years ago

  • 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.

comment:4 @M66B4 years ago

  • 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.

comment:5 @nacin4 years ago

  • 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.

comment:6 @M66B4 years ago

Thanks for your support!

Note: See TracTickets for help on using tickets.