Ticket #34175: 34175.taxonomy-functions.php.patch
| File 34175.taxonomy-functions.php.patch, 2.6 KB (added by , 10 years ago) |
|---|
-
wp-includes/taxonomy-functions.php
1411 1411 } 1412 1412 1413 1413 $terms = $wpdb->get_results($query); 1414 if ( 'all' == $_fields ) { 1414 $term_ids = wp_list_pluck( $terms, 'term_id' ); 1415 if ( 'all' == $_fields && !empty( $has_term_ids ) ) { 1415 1416 update_term_cache( $terms ); 1416 1417 } 1417 1418 1418 1419 // Prime termmeta cache. 1419 if ( $args['update_term_meta_cache'] ) { 1420 $term_ids = wp_list_pluck( $terms, 'term_id' ); 1420 if ( $args['update_term_meta_cache'] && $term_ids ) { 1421 1421 update_termmeta_cache( $term_ids ); 1422 1422 } 1423 1423 … … 1428 1428 return apply_filters( 'get_terms', array(), $taxonomies, $args ); 1429 1429 } 1430 1430 1431 if ( $child_of ) {1431 if ( $child_of && $term_ids ) { 1432 1432 foreach ( $taxonomies as $_tax ) { 1433 1433 $children = _get_term_hierarchy( $_tax ); 1434 1434 if ( ! empty( $children ) ) { … … 1438 1438 } 1439 1439 1440 1440 // Update term counts to include children. 1441 if ( $args['pad_counts'] && 'all' == $_fields ) {1441 if ( $args['pad_counts'] && 'all' == $_fields && $term_ids ) { 1442 1442 foreach ( $taxonomies as $_tax ) { 1443 1443 _pad_term_counts( $terms, $_tax ); 1444 1444 } … … 1445 1445 } 1446 1446 1447 1447 // Make sure we show empty categories that have children. 1448 if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) {1448 if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) && $term_ids ) { 1449 1449 foreach ( $terms as $k => $term ) { 1450 1450 if ( ! $term->count ) { 1451 1451 $children = get_term_children( $term->term_id, $term->taxonomy ); … … 1465 1465 } 1466 1466 1467 1467 $_terms = array(); 1468 if ( 'id=>parent' == $_fields ) {1468 if ( 'id=>parent' == $_fields && $term_ids ) { 1469 1469 foreach ( $terms as $term ) { 1470 1470 $_terms[ $term->term_id ] = $term->parent; 1471 1471 } 1472 } elseif ( 'ids' == $_fields ) {1472 } elseif ( 'ids' == $_fields && $term_ids ) { 1473 1473 foreach ( $terms as $term ) { 1474 1474 $_terms[] = $term->term_id; 1475 1475 } 1476 } elseif ( 'names' == $_fields ) {1476 } elseif ( 'names' == $_fields && !empty( wp_list_pluck( $terms, 'name' ) ) ) { 1477 1477 foreach ( $terms as $term ) { 1478 1478 $_terms[] = $term->name; 1479 1479 } 1480 } elseif ( 'id=>name' == $_fields ) {1480 } elseif ( 'id=>name' == $_fields && $term_ids && !empty( wp_list_pluck( $terms, 'name' ) ) ) { 1481 1481 foreach ( $terms as $term ) { 1482 1482 $_terms[ $term->term_id ] = $term->name; 1483 1483 } 1484 } elseif ( 'id=>slug' == $_fields ) {1484 } elseif ( 'id=>slug' == $_fields && $term_ids && !empty( wp_list_pluck( $terms, 'slug' ) ) ) { 1485 1485 foreach ( $terms as $term ) { 1486 1486 $_terms[ $term->term_id ] = $term->slug; 1487 1487 }