WordPress.org

Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#53443 new defect (bug)

The value of the `post_count` meta field is wrong because it doesn't get decremented when a post is deleted

Reported by: henry.wright Owned by:
Milestone: 5.9 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: multisite Cc:

Description

The update_posts_count() function is used to update a blog's post count. When a post is added to the database the post_count value is incremented as expected. However, when a post is deleted, the post_count value isn't decremented.

This is because the _update_posts_count_on_delete() function, which calls update_posts_count() is hooked to the delete_post action.

delete_post fires immediately before a post is deleted from the database.

Therefore, the query performed in update_posts_count() to get the post count is run at the wrong time.

The solution is to use the deleted_post hook instead of the delete_post hook.

Attachments (1)

53443.diff (738 bytes) - added by henry.wright 5 weeks ago.

Download all attachments as: .zip

Change History (3)

@henry.wright
5 weeks ago

#1 @henry.wright
5 weeks ago

  • Keywords has-patch added

53443.diff uses the deleted_post hook instead of the delete_post hook

#2 @SergeyBiryukov
5 weeks ago

  • Component changed from General to Posts, Post Types
  • Focuses multisite added
  • Milestone changed from Awaiting Review to 5.9
Note: See TracTickets for help on using tickets.