W3cubDocs

/WordPress

wp_list_pluck( array $input_list, int|string $field, int|string $index_key = null ): array

Plucks a certain field out of each object or array in an array.

Description

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

Parameters

$input_listarrayrequired
List of objects or arrays.
$fieldint|stringrequired
Field from the object to place instead of the entire object.
$index_keyint|stringoptional
Field from the object to use as keys for the new array.

Default:null

Return

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 $input_list will be preserved in the results.

Source

function wp_list_pluck( $input_list, $field, $index_key = null ) {
	if ( ! is_array( $input_list ) ) {
		return array();
	}

	$util = new WP_List_Util( $input_list );

	return $util->pluck( $field, $index_key );
}

Changelog

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

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_list_pluck