Title: wp_unique_id_from_values
Published: April 28, 2025
Last modified: May 20, 2026

---

# wp_unique_id_from_values( array $data, string $prefix = '' ): string

## In this article

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

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

Generates a unique ID based on the structure and values of a given array.

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

This function serializes the array into a JSON string and generates a hash that 
serves as a unique identifier. Optionally, a prefix can be added to the generated
ID for context or categorization.

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

 `$data`arrayrequired

The input array to generate an ID from.

`$prefix`stringoptional

A prefix to prepend to the generated ID.

Default:`''`

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

 string The generated unique ID for the array.

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

    ```php
    function wp_unique_id_from_values( array $data, string $prefix = '' ): string {
    	if ( empty( $data ) ) {
    		_doing_it_wrong(
    			__FUNCTION__,
    			sprintf(
    				/* translators: %s: The parameter name. */
    				__( 'The %s parameter must not be empty.' ),
    				'$data'
    			),
    			'6.8.0'
    		);
    	}

    	$serialized = wp_json_encode( $data );
    	$hash       = substr( md5( $serialized ), 0, 8 );

    	return $prefix . $hash;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/functions.php#L8118)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/functions.php#L8118-L8135)

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

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

Encodes a variable into JSON, with some confidence checks.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

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

Marks something as being incorrectly called.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_unique_id_from_values/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_unique_id_from_values/?output_format=md#)

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

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

## User Contributed Notes

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