diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php
index 2f3da47..d0aa445 100644
|
a
|
b
|
class WP_Term_Query { |
| 686 | 686 | return $this->terms; |
| 687 | 687 | } |
| 688 | 688 | |
| | 689 | /** |
| | 690 | * Filters the terms array before the query takes place. |
| | 691 | * |
| | 692 | * Return a non-null value to bypass WordPress's default terms queries. |
| | 693 | * |
| | 694 | * @param array|null $terms Return an array of term data to short-circuit WP's query, |
| | 695 | * or null to allow WP to run its normal queries. |
| | 696 | * @param WP_Term_Query $this The WP_Term_Query instance, passed by reference. |
| | 697 | */ |
| | 698 | $terms = apply_filters_ref_array( 'terms_pre_query', array( null, &$this ) ); |
| | 699 | |
| 689 | 700 | if ( 'count' == $_fields ) { |
| 690 | | $count = $wpdb->get_var( $this->request ); |
| 691 | | wp_cache_set( $cache_key, $count, 'terms' ); |
| 692 | | return $count; |
| 693 | | } |
| | 701 | if( null === $terms ) { |
| | 702 | $count = $wpdb->get_var( $this->request ); |
| | 703 | wp_cache_set( $cache_key, $count, 'terms' ); |
| | 704 | return $count; |
| | 705 | } |
| 694 | 706 | |
| 695 | | $terms = $wpdb->get_results( $this->request ); |
| 696 | | if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { |
| 697 | | update_term_cache( $terms ); |
| | 707 | return count( $terms ); |
| 698 | 708 | } |
| 699 | 709 | |
| 700 | | // Prime termmeta cache. |
| 701 | | if ( $args['update_term_meta_cache'] ) { |
| 702 | | $term_ids = wp_list_pluck( $terms, 'term_id' ); |
| 703 | | update_termmeta_cache( $term_ids ); |
| 704 | | } |
| | 710 | if( null === $terms ) { |
| | 711 | $terms = $wpdb->get_results( $this->request ); |
| | 712 | if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { |
| | 713 | update_term_cache( $terms ); |
| | 714 | } |
| 705 | 715 | |
| 706 | | if ( empty( $terms ) ) { |
| 707 | | wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); |
| 708 | | return array(); |
| 709 | | } |
| | 716 | // Prime termmeta cache. |
| | 717 | if ( $args['update_term_meta_cache'] ) { |
| | 718 | $term_ids = wp_list_pluck( $terms, 'term_id' ); |
| | 719 | update_termmeta_cache( $term_ids ); |
| | 720 | } |
| 710 | 721 | |
| 711 | | if ( $child_of ) { |
| 712 | | foreach ( $taxonomies as $_tax ) { |
| 713 | | $children = _get_term_hierarchy( $_tax ); |
| 714 | | if ( ! empty( $children ) ) { |
| 715 | | $terms = _get_term_children( $child_of, $terms, $_tax ); |
| | 722 | if ( empty( $terms ) ) { |
| | 723 | wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); |
| | 724 | return array(); |
| | 725 | } |
| | 726 | |
| | 727 | if ( $child_of ) { |
| | 728 | foreach ( $taxonomies as $_tax ) { |
| | 729 | $children = _get_term_hierarchy( $_tax ); |
| | 730 | if ( ! empty( $children ) ) { |
| | 731 | $terms = _get_term_children( $child_of, $terms, $_tax ); |
| | 732 | } |
| 716 | 733 | } |
| 717 | 734 | } |
| 718 | | } |
| 719 | 735 | |
| 720 | | // Update term counts to include children. |
| 721 | | if ( $args['pad_counts'] && 'all' == $_fields ) { |
| 722 | | foreach ( $taxonomies as $_tax ) { |
| 723 | | _pad_term_counts( $terms, $_tax ); |
| | 736 | // Update term counts to include children. |
| | 737 | if ( $args['pad_counts'] && 'all' == $_fields ) { |
| | 738 | foreach ( $taxonomies as $_tax ) { |
| | 739 | _pad_term_counts( $terms, $_tax ); |
| | 740 | } |
| 724 | 741 | } |
| 725 | | } |
| 726 | 742 | |
| 727 | | // Make sure we show empty categories that have children. |
| 728 | | if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) { |
| 729 | | foreach ( $terms as $k => $term ) { |
| 730 | | if ( ! $term->count ) { |
| 731 | | $children = get_term_children( $term->term_id, $term->taxonomy ); |
| 732 | | if ( is_array( $children ) ) { |
| 733 | | foreach ( $children as $child_id ) { |
| 734 | | $child = get_term( $child_id, $term->taxonomy ); |
| 735 | | if ( $child->count ) { |
| 736 | | continue 2; |
| | 743 | // Make sure we show empty categories that have children. |
| | 744 | if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) { |
| | 745 | foreach ( $terms as $k => $term ) { |
| | 746 | if ( ! $term->count ) { |
| | 747 | $children = get_term_children( $term->term_id, $term->taxonomy ); |
| | 748 | if ( is_array( $children ) ) { |
| | 749 | foreach ( $children as $child_id ) { |
| | 750 | $child = get_term( $child_id, $term->taxonomy ); |
| | 751 | if ( $child->count ) { |
| | 752 | continue 2; |
| | 753 | } |
| 737 | 754 | } |
| 738 | 755 | } |
| 739 | | } |
| 740 | 756 | |
| 741 | | // It really is empty. |
| 742 | | unset( $terms[ $k ] ); |
| | 757 | // It really is empty. |
| | 758 | unset( $terms[ $k ] ); |
| | 759 | } |
| 743 | 760 | } |
| 744 | 761 | } |
| 745 | 762 | } |