#46441 closed defect (bug) (duplicate)
[WordPress - 5.1] Can't get categories after publishing the post first time on using "transition_post_status" action
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.0 |
Component: | REST API | Keywords: | needs-patch |
Focuses: | Cc: |
Description
When we publish the Post for the first time without doing "Save draft" at that time we are not getting post categories in the function which is bind to "transition_post_status" status hook.
We are using "get_the_category" method to get the categories. But, every time it returns default category.
It works when we do "Save draft" and then "Publish" it.
I suspect it's related to WP_REST_Posts_Controller where "wp_update_post" method is called and we are not passing "selected categories" into data and in "wp_update_post" it overwrites post categories with default category if it's not set.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Hi @malayladu and welcome to trac!
This is due to the issue detailed in #45114, post meta and terms (tags, categories, custom taxonomies) are not updated until after
wp_update_post()
runs so the details are not available when saving via the REST API, which the new editor uses.Some ideas have been presented but a way forward hasn't been decided yet, I am afraid.
I'm marking this ticket as duplicate so discussion can continue in one place on #45114.