[wp-trac] [WordPress Trac] #55239: Filter hook wp_sitemaps_taxonomies_entry passes Term ID not Object

WordPress Trac noreply at wordpress.org
Wed Feb 23 15:02:44 UTC 2022

#55239: Filter hook wp_sitemaps_taxonomies_entry passes Term ID not Object
 Reporter:  RavanH        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Sitemaps      |    Version:  5.9.1
 Severity:  minor         |   Keywords:
  Focuses:                |
 The filter hook `wp_sitemaps_taxonomies_entry` in wp-
 includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php line 125
 `$term` parameter is announced as being a `WP_Term` object but it is
 actually the term ID. This is caused by the default query argument

 I worked around it by adding the filter:
 add_filter( 'wp_sitemaps_taxonomies_query_args', function($args) {
 $args['fields'] = 'all'; return $args; } );

 To fix this, I'd suggest ''either'' forcing the fields argument to "all"
 by adding
 $args['fields'] = 'all';
 before the WP_Term_Query on line 102 ''or'' changing the filter hook
 `@param WP_Term $term Term object.` description to reflect that `$term`
 can be different things depening on what is passed into the term query
 fields argument.

 My preference would be the first suggestion, as that would generate the
 most predictable behavior and most usefull data passed through the filter.
 But then again, it might break plugins that are currently using the filter
 and expecting an ID...

Ticket URL: <https://core.trac.wordpress.org/ticket/55239>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list