Make WordPress Core

Opened 6 years ago

Last modified 6 years ago

#45076 new defect (bug)

Category counter is not updated

Reported by: mukesh27's profile mukesh27 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: needs-patch needs-testing has-screenshots dev-feedback
Focuses: administration Cc:

Description

When we create new category from admin panel category successfully added in right category panel but it's counter is not updated.

Suppose i have create five category like ''Category 1'', ''Category 1.1'', ''Category 2'', ''Category 2.1'', ''Uncategorized'' system show counter as 5 items but when i create new category called ''Category 3'' it will added successfully in category list but total counter still show 5 items it should show 6 items but when i refresh that page it show counter as 6 items.

Check video https://youtu.be/rBmziC5_0XQ

Change History (2)

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


6 years ago

#2 @strangerstudios
6 years ago

I've confirmed that the item count (for total cats, not posts per cat) does NOT update when adding a new category. It also doesn't update when deleting a category.

Tested in WordPress 5.0

This is because the form submission is handled by AJAX. The AJAX response does not include the count or JS code to update it.

Here is the AJAX handler in PHP:
https://github.com/WordPress/WordPress/blob/5.0-branch/wp-admin/includes/ajax-actions.php#L877-L930

Here is the JS that kicks off and processes that response:
https://github.com/WordPress/WordPress/blob/5.0-branch/wp-admin/js/tags.js#L89-L146

We could update the wp_ajax_add_tag() function in ajax-actions.php to query for the count of categories and return that in the AJAX response. Then update tags.js to process that to update the counts on the screen.

Alternatively, we could just update the JS to increment or decrement the items number when a category is added or removed. I think this would be good enough even if it would be incorrect when multiple admins are updating categories from different screens.

This is also fairly minor and may not be worth fixing.

Note: See TracTickets for help on using tickets.