Opened 6 years ago
Closed 6 years ago
#4500 closed defect (bug) (fixed)
wp_update_term_count is not increasing taxonomy count correctly.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.3 |
| Component: | Administration | Version: | 2.3 |
| Severity: | major | Keywords: | has-patch |
| Cc: | ron@… |
Description
It appears that wp_set_object_terms is not always increasing the taxonomy count. When using the following code, the count is not increased:
register_taxonomy('podcast_format', 'custom_field');
wp_insert_term('Main Feed', 'podcast_format'); Run only once to create term
wp_set_object_terms($custom_field_id, 'main-feed', 'podcast_format', false);
I am aware of wp_update_term_count, but shouldn't wp_set_object_terms increase the count for us?
Attachments (1)
Change History (4)
comment:1
cavemonkey50 — 6 years ago
- Cc ron@… added
- Keywords has-patch added
- Milestone set to 2.3 (trunk)
- Severity changed from normal to major
cavemonkey50 — 6 years ago
comment:2
cavemonkey50 — 6 years ago
- Summary changed from wp_set_object_terms is not increasing taxonomy count correctly. to wp_update_term_count is not increasing taxonomy count correctly.
Note: See
TracTickets for help on using
tickets.

I've tracked down the problem. wp_update_term_count is checking if $taxonomy->update_count_callback is set to a custom update function. The problem is $taxonomy->update_count_callback is always set to a default value of null. My attached patch also checks to see if the $taxonomy->update_count_callback is not set to null.
In addition, even once you get past that step, the actual update function needed to be in a foreach loop. My attached patch corrects this issue also.
Finally, I would just like to clarify that this not only affects custom taxonomies, but the taxonomy link_category also. link_category is not using a custom update function, therefore falls into this defect.