WordPress at Your Fingertips

wp_list_pluck() WP 1.0

Pluck a certain field out of each object in a list.

This has the same functionality and prototype of array_column() (PHP 5.5) but also supports objects.

1 time — 0.00001 sec (speed of light) | 50000 times — 0.45 sec (very fast)

No Hooks.


Array. Array of found values. If $index_key is set, an array of found values with keys corresponding to $index_key. If $index_key is null, array keys from the original $list will be preserved in the results.


wp_list_pluck( $list, $field, $index_key );
$list(array) (required)
List of objects or arrays
$field(int|string) (required)
Field from the object to place instead of the entire object
Field from the object to use as keys for the new array.
Default: null


Since 3.1.0 Introduced.
Since 4.0.0 $index_key parameter added.
Since 4.7.0 Uses WP_List_Util class.

Code of wp_list_pluck() WP 5.7.2

function wp_list_pluck( $list, $field, $index_key = null ) {
	$util = new WP_List_Util( $list );
	return $util->pluck( $field, $index_key );

From tag: array list help functions (sorting arrays objects)

More from category: Helper Functions

No comments
    Log In