[wp-trac] [WordPress Trac] #53443: The value of the `post_count` meta field is wrong because it doesn't get decremented when a post is deleted
WordPress Trac
noreply at wordpress.org
Thu Jun 17 15:08:01 UTC 2021
#53443: The value of the `post_count` meta field is wrong because it doesn't get
decremented when a post is deleted
--------------------------+-----------------------------
Reporter: henry.wright | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53443>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list