wip
This commit is contained in:
@@ -470,14 +470,11 @@ class WP_Term_Query {
|
||||
$exclude_tree = $args['exclude_tree'];
|
||||
$include = $args['include'];
|
||||
|
||||
$inclusions = '';
|
||||
if ( ! empty( $include ) ) {
|
||||
$exclude = '';
|
||||
$exclude_tree = '';
|
||||
$inclusions = implode( ',', wp_parse_id_list( $include ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $inclusions ) ) {
|
||||
$this->sql_clauses['where']['inclusions'] = 't.term_id IN ( ' . $inclusions . ' )';
|
||||
}
|
||||
|
||||
@@ -777,8 +774,9 @@ class WP_Term_Query {
|
||||
}
|
||||
|
||||
if ( $args['cache_results'] ) {
|
||||
$cache_key = $this->generate_cache_key( $args, $this->request );
|
||||
$cache = wp_cache_get( $cache_key, 'term-queries' );
|
||||
$cache_key = $this->generate_cache_key( $args, $this->request );
|
||||
$last_changed = wp_cache_get_last_changed( 'terms' );
|
||||
$cache = wp_cache_get_salted( $cache_key, 'term-queries', $last_changed );
|
||||
|
||||
if ( false !== $cache ) {
|
||||
if ( 'ids' === $_fields ) {
|
||||
@@ -806,7 +804,7 @@ class WP_Term_Query {
|
||||
if ( 'count' === $_fields ) {
|
||||
$count = $wpdb->get_var( $this->request ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
if ( $args['cache_results'] ) {
|
||||
wp_cache_set( $cache_key, $count, 'term-queries' );
|
||||
wp_cache_set_salted( $cache_key, $count, 'term-queries', $last_changed );
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
@@ -814,10 +812,13 @@ class WP_Term_Query {
|
||||
$terms = $wpdb->get_results( $this->request ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
|
||||
if ( empty( $terms ) ) {
|
||||
$this->terms = array();
|
||||
|
||||
if ( $args['cache_results'] ) {
|
||||
wp_cache_add( $cache_key, array(), 'term-queries' );
|
||||
wp_cache_set_salted( $cache_key, $this->terms, 'term-queries', $last_changed );
|
||||
}
|
||||
return array();
|
||||
|
||||
return $this->terms;
|
||||
}
|
||||
|
||||
$term_ids = wp_list_pluck( $terms, 'term_id' );
|
||||
@@ -849,7 +850,8 @@ class WP_Term_Query {
|
||||
if ( is_array( $children ) ) {
|
||||
foreach ( $children as $child_id ) {
|
||||
$child = get_term( $child_id, $term->taxonomy );
|
||||
if ( $child->count ) {
|
||||
|
||||
if ( $child instanceof WP_Term && $child->count ) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
@@ -899,7 +901,7 @@ class WP_Term_Query {
|
||||
}
|
||||
|
||||
if ( $args['cache_results'] ) {
|
||||
wp_cache_add( $cache_key, $term_cache, 'term-queries' );
|
||||
wp_cache_set_salted( $cache_key, $term_cache, 'term-queries', $last_changed );
|
||||
}
|
||||
|
||||
$this->terms = $this->format_terms( $term_objects, $_fields );
|
||||
@@ -1171,8 +1173,8 @@ class WP_Term_Query {
|
||||
// Replace wpdb placeholder in the SQL statement used by the cache key.
|
||||
$sql = $wpdb->remove_placeholder_escape( $sql );
|
||||
|
||||
$key = md5( serialize( $cache_args ) . $sql );
|
||||
$last_changed = wp_cache_get_last_changed( 'terms' );
|
||||
return "get_terms:$key:$last_changed";
|
||||
$key = md5( serialize( $cache_args ) . $sql );
|
||||
|
||||
return "get_terms:$key";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user