Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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: malayladu's profile malayladu 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)

This ticket was mentioned in Slack in #core by malayladu. View the logs.


4 years ago

#2 @peterwilsoncc
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version changed from 5.1 to 5.0

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.

#3 @malayladu
4 years ago

Ok.

Got it.

Note: See TracTickets for help on using tickets.