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

In this article

Generate cache key.

Parameters

$argsarrayrequired
WP_Term_Query arguments.
$sqlstringrequired
SQL statement.

Return

string Cache key.

Source

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['cache_results'], $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";
}

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

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