Title: WP_REST_Pattern_Directory_Controller::get_transient_key
Published: May 25, 2022
Last modified: May 20, 2026

---

# WP_REST_Pattern_Directory_Controller::get_transient_key( array $query_args ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#wp--skip-link--target)

Include a hash of the query args, so that different requests are stored in separate
caches.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#description)󠁿

MD5 is chosen for its speed, low-collision rate, universal availability, and to 
stay under the character limit for `_site_transient_timeout_{...}` keys.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#parameters)󠁿

 `$query_args`arrayrequired

Query arguments to generate a transient key from.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#return)󠁿

 string Transient key.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#source)󠁿

    ```php
    protected function get_transient_key( $query_args ) {

    	if ( isset( $query_args['slug'] ) ) {
    		// This is an additional precaution because the "sort" function expects an array.
    		$query_args['slug'] = wp_parse_list( $query_args['slug'] );

    		// Empty arrays should not affect the transient key.
    		if ( empty( $query_args['slug'] ) ) {
    			unset( $query_args['slug'] );
    		} else {
    			// Sort the array so that the transient key doesn't depend on the order of slugs.
    			sort( $query_args['slug'] );
    		}
    	}

    	return 'wp_remote_block_patterns_' . md5( serialize( $query_args ) );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php#L391)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php#L391-L407)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_parse_list()](https://developer.wordpress.org/reference/functions/wp_parse_list/)`wp-includes/functions.php` |

Converts a comma- or space-separated list of scalar values to an array.

  |

| Used by | Description | 
| [WP_REST_Pattern_Directory_Controller::get_items()](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_items/)`wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php` |

Search and retrieve block patterns metadata

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/get_transient_key/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_pattern_directory_controller%2Fget_transient_key%2F)
before being able to contribute a note or feedback.