[wp-trac] [WordPress Trac] #38280: Make term count for a specific object type available

WordPress Trac noreply at wordpress.org
Sat Jun 23 17:22:32 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 boonebgorges):

 [attachment:38280.15.diff] is a rethink.

 In the case of post types, term-object counts will be regenerated whenever
 `wp_update_term_count_now()` is run. This, in turn, is triggered by
 `wp_set_object_terms()`, etc. In other words, the data should always exist
 for terms that are touched after the 5.0 release - that is, those that are
 created/updated/attached to posts/removed from posts after 5.0. The time
 when we need to worry about "backfilling" the data is for terms that have
 *not* been touched since 5.0.

 In the case of non-post-types (or post types that have their own custom
 `update_count_callback`), there is nothing that core can do when the count
 is requested, except to fail gracefully.

 To accommodate both scenarios with a single approach, I introduced a new
 action 'wp_no_object_term_count_found'. Core will hook into it for post
 types, and will run `wp_update_term_count_now()`. (This covers "legacy"
 terms.) For non-post-types or post types with custom
 `update_count_callback`, plugins can hook to it and populate the object-
 term counts, and/or use the main filter I've added at the end of the
 function.

 How does this general approach feel to others?

 Moving forward, can we think about new names for the
 function/functionality? `term_count_for_object_type()` sounds backward -
 the thing being counted is "objects of a given (object/post) type that
 have a given term", not "terms that belong to a given (object/post) type".
 How about `wp_get_term_object_count()`? I can't think of anything more
 melodious :)

 I also have questions about the "if" conditions where I put the comment
 `are these right?`. I know that these are meant to be shortcuts, but I
 worry that they have the potential to produce corrupted data. For example,
 the `1 >= count( $taxonomy_object->object_type )` call assumes that
 plugins have properly registered their taxonomies with object types - but
 do we enforce this elsewhere? What if the `$taxonomy_object->object_type`
 is not the same as `$object_type`? It seems better to return no data in
 these cases than to return something potentially incorrect. Can anyone
 help to think through the possibilities here?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/38280#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list