[wp-trac] [WordPress Trac] #32942: Taxomony term list counts do not respect post_type parameter

WordPress Trac noreply at wordpress.org
Sat Aug 29 02:45:30 UTC 2015


#32942: Taxomony term list counts do not respect post_type parameter
-------------------------------------+-----------------------------
 Reporter:  stueynet                 |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  Taxonomy                 |     Version:  3.1
 Severity:  normal                   |  Resolution:
 Keywords:  ux-feedback needs-patch  |     Focuses:  administration
-------------------------------------+-----------------------------

Comment (by boonebgorges):

 Replying to [comment:3 stueynet]:
 > Just thought I would follow up a bit on this one. After examining the
 code the issue is that the $tag object which is used to display the count
 in the Count column of the terms table, uses get_terms. get_terms does not
 care about post_type. So this could never have worked.

 Yes, this sounds correct.

 > So the solution is to add the ability to set a post_type parameter to
 the get_terms() function. Then updated the call to get_terms above to
 include that parameter.

 A `'post_type'` argument for `get_terms()` probably is not going to
 happen. Read #18106 for some back story, but basically (a) the taxonomy
 component is object-type agnostic - by design, it doesn't know anything
 about posts, (b) the table joins that would be required would perform
 horrendously. For the case of this list table, we'll probably have to do
 something like this:

 {{{
 $posts_in_post_type = get_posts( array(
     'fields' => 'ids',
     'post_type' => $this->screen->post_type,
     'posts_per_page' => -1,
 ) );

 $args['include'] = = wp_get_object_terms( $posts_in_post_type, $taxonomy,
 array( 'ids' ) );
 $terms = get_terms( $taxonomy, $args );
 }}}

 This is not the most elegant thing in the world, but I think it's probably
 OK for these term tables.

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


More information about the wp-trac mailing list