WP_Term_Query::generate_cache_key( array $args, string $sql ): string

Generate cache key.


Parameters

$args array Required
WP_Term_Query arguments.
$sql string Required
SQL statement.

Top ↑

Return

string Cache key.


Top ↑

Source

File: wp-includes/class-wp-term-query.php. View all references

protected function generate_cache_key( array $args, $sql ) {
	global $wpdb;
	// $args can be anything. Only use the args defined in defaults to compute the key.
	$cache_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) );

	unset( $cache_args['update_term_meta_cache'] );

	if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) {
		$cache_args['fields'] = 'all';
	}
	$taxonomies = (array) $args['taxonomy'];

	// Replace wpdb placeholder in the SQL statement used by the cache key.
	$sql = $wpdb->remove_placeholder_escape( $sql );

	$key          = md5( serialize( $cache_args ) . serialize( $taxonomies ) . $sql );
	$last_changed = wp_cache_get_last_changed( 'terms' );
	return "get_terms:$key:$last_changed";
}


Top ↑

Changelog

Changelog
Version Description
6.2.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.