wp_parse_slug_list()
Creates an array of tags from a string of words separated by commas, spaces. The values of the array are cleaned using sanitize_title().
An array can be passed to simply clean it.
The array will only contain unique values.
Uses: sanitize_title()
1 time — 0.000199 sec (fast) | 50000 times — 3.64 sec (fast) | PHP 7.0.8, WP 4.7
No Hooks.
Returns
string[]. Cleaned array of tags (slugs).
Usage
wp_parse_slug_list( $input_list ): array;
- $list(array/string) (required)
- List of tags (slug) as a string. Tags must be separated by spaces or commas. For example:
my_slug, your_slug.
Examples
#1 Demonstration of work
$str = 'Hello, World Hello, World'; $array = wp_parse_slug_list( $str ); /* $array will be equal to: Array ( [0] => hello [1] => world ) */ // the following lines will return the same result: $atr = 'Hello world'; $atr = 'Hello, world'; $atr = 'Hello, world, world,world;' $atr = 'Hello, world';
Transliteration will be made only if the corresponding plugin is installed, for example, Cyr to Lat.
Changelog
| Since 4.7.0 | Introduced. |
| Since 5.1.0 | Refactored to use wp_parse_list(). |
wp_parse_slug_list() wp parse slug list code WP 7.1
function wp_parse_slug_list( $input_list ): array {
$input_list = wp_parse_list( $input_list );
return array_unique(
array_map(
'sanitize_title',
array_map(
/*
* Cast booleans, integers, and floats to strings. Non-scalar types
* (including null) have already been filtered out by wp_parse_list().
*/
'strval',
$input_list
)
)
);
}