Skip to content

Commit de170c0

Browse files
committed
Taxonomy: Cache term objects in WP_Term_Query if query is filtered.
When utilizing the `terms_clauses` or `get_terms_fields` filters within `WP_Term_Query` and the selected fields are modified, the entire term object is now cached. This adjustment is necessary because filters can broaden the selected fields beyond just the term ID. Fields linked to the term object, such as the count or parent, may undergo modifications when queried. Caching the complete object ensures the accurate storage of these modified fields within the cache. Props spacedmonkey, tnolte, peterwilsoncc. Fixes #58116. Built from https://develop.svn.wordpress.org/trunk@56555 git-svn-id: http://core.svn.wordpress.org/trunk@56067 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 4920adb commit de170c0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

wp-includes/class-wp-term-query.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ public function get_terms() {
738738
$order = isset( $clauses['order'] ) ? $clauses['order'] : '';
739739
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
740740

741+
$fields_is_filtered = implode( ', ', $selects ) !== $fields;
742+
741743
if ( $where ) {
742744
$where = "WHERE $where";
743745
}
@@ -782,7 +784,7 @@ public function get_terms() {
782784
$cache = array_map( 'intval', $cache );
783785
} elseif ( 'count' !== $_fields ) {
784786
if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) )
785-
|| ( 'all' === $_fields && $args['pad_counts'] )
787+
|| ( 'all' === $_fields && $args['pad_counts'] || $fields_is_filtered )
786788
) {
787789
$term_ids = wp_list_pluck( $cache, 'term_id' );
788790
} else {
@@ -884,6 +886,8 @@ public function get_terms() {
884886
$object->count = $term->count;
885887
$term_cache[] = $object;
886888
}
889+
} elseif ( $fields_is_filtered ) {
890+
$term_cache = $term_objects;
887891
} else {
888892
$term_cache = wp_list_pluck( $term_objects, 'term_id' );
889893
}

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.4-alpha-56554';
19+
$wp_version = '6.4-alpha-56555';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)