Opened 7 years ago
Last modified 4 months ago
#45076 new defect (bug)
Category counter is not updated
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Taxonomy | Keywords: | needs-testing has-screenshots dev-feedback has-patch |
| 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 (6)
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
7 years ago
This ticket was mentioned in PR #9336 on WordPress/wordpress-develop by @hbhalodia.
4 months ago
#4
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/45076
#5
@
4 months ago
Hi @mukesh27, @sourav08, @strangerstudios,
In addition to incrementing the category count when adding a term, it is also necessary to decrement the count when deleting a single term to ensure accuracy.
I have observed that for both add and delete operations, we trigger an AJAX call to insert or remove the term from the site. Upon successful completion, the term count should be updated accordingly by incrementing or decrementing by one, utilizing the count value already displayed on the current page.
Please find the pull request implementing this functionality here: [PR](https://github.com/WordPress/wordpress-develop/pull/9336)
That said, there are a couple of points to consider:
- When new tags are added, the count is initially hidden. To display it properly, we need to apply styles dynamically via JavaScript to remove the
display: noneattribute. - When the count changes from singular to plural or vice versa (e.g., from "1 item" to "2 items"), the current logic only appends 's' to form the plural, which does not accommodate localization. Since
item/itemsis a localized string, pluralization varies across languages. Consequently, handling this pluralization programmatically based on the count is not feasible within the current framework. This issue also applies in reverse when decrementing from plural to singular.
Please let me know if you have any suggestions or further insights on handling the localization nuances.
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.