[wp-trac] [WordPress Trac] #27918: get_taxonomies() on single post type should return taxonomies registered on multiple post types

WordPress Trac noreply at wordpress.org
Fri Apr 25 15:28:43 UTC 2014


#27918: get_taxonomies() on single post type should return taxonomies registered on
multiple post types
------------------------------------------+--------------------
 Reporter:  johnrork                      |       Owner:
     Type:  defect (bug)                  |      Status:  new
 Priority:  normal                        |   Milestone:  4.0
Component:  Taxonomy                      |     Version:  trunk
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:
------------------------------------------+--------------------

Comment (by bobbingwide):

 I'm at a WordPress Contributor day in Sheffield. I've developed a fix for
 this problem. Patch coming soon but basically it's this.
 In wp_list_filter() replace the second foreach loop to

 {{{
 foreach ( $args as $m_key => $m_value ) {
         if ( array_key_exists( $m_key, $to_match ) && $m_value ==
 $to_match[ $m_key ] )
                 $matched++;
 }
 }}}
 to cater for $m_value being an array.

 {{{
 foreach ( $args as $m_key => $m_value ) {
         if ( array_key_exists( $m_key, $to_match ) ) {
           if ( $m_value == $to_match[ $m_key ] ) {
             $matched++;
           }
           elseif ( is_array( $m_value ) && is_array( $to_match[ $m_key ] )
 ) {
             foreach ( $m_value as $mv_key => $mv_value ) {
               if ( in_array( $mv_value, $to_match[ $m_key ] ) ) {
                 $matched = $count;
               }
             }
 }
 }}}
 We also check that $to_match[ $m_key ] is an array before checking for the
 presence of each given value ( $mv_value ). If ANY of the fields is found
 then the value of $matched is set to $count so that the following tests on
 the operator will pass.
 Note: I haven't tested with different values of operator - just used
 default 'AND'.

 I developed a shortcode to test the changes.
 With no parameters passed it returns a list of all registered post types
 with each of their taxonomy names.
 With a post_types=a,b,c parameter the list of taxonomies returned is the
 set of taxonomies associated with any of the post types.

 e.g. for post,page it returns category post_tag post_format
 for page,post,nav_menu_item,revision is returns category post_tag nav_menu
 post_format

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


More information about the wp-trac mailing list