[wp-trac] [WordPress Trac] #38280: Make term count for a specific object type available
WordPress Trac
noreply at wordpress.org
Fri Sep 21 20:57:44 UTC 2018
#38280: Make term count for a specific object type available
--------------------------------------+------------------------------
Reporter: desrosj | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.7
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------------
Comment (by desrosj):
Diving back into this today, I thought of an issue with the conditionals
in `wp_get_term_object_count()`. The first condition checked is `0 ===
$term->count`. If the object types registered to a taxonomy change and the
count is 0, a recount will not occur until a term is added or removed from
an object. This could result in inaccurate counts,
Maybe we have been thinking about this the wrong way. Maybe, instead of
checking the number of object types registered to a taxonomy (which could
be the same even if you remove one taxonomy and add another), the object
types themselves should be compared. Something like:
{{{
$new_types = array_diff( $registered_object_types, $counted_object_types
);
$missing_counted_types = array_diff( $counted_object_types,
$registered_object_types );
if ( ! empty( $new_types ) || ! empty( $missing_counted_types ) {
// Object types have changed. Recount.
} elseif ( 0 === $term->count ) {
// Check for 0 count.
} else {
$count = wp_get_term_object_count_from_meta( $term_id, $object_type );
}
}}}
This would also require `_wp_counted_object_types` for ''every'' term,
which I am also undecided on and want to think about a bit more. The only
alternative I can think of in the current state is storing a cache as an
option when there is only one object type on a taxonomy. But, I think that
introduces some needless complexity.
> What information would the error provide to a developer?
The scenarios where a count could not be determined, I think, are:
- An error occurred trying to recount
- Post type does not exist.
- A custom callback was not properly implemented.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38280#comment:28>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list