wp_list_pluck

Definition:
function wp_list_pluck( $list, $field ) {}

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

Parameters

  • array $list: A list of objects or arrays
  • int|string $field: A field from the object to place instead of the entire object

Source code

function wp_list_pluck( $list, $field ) {

	foreach ( $list as $key => $value ) {

		if ( is_object( $value ) )

			$list[ $key ] = $value->$field;

		else

			$list[ $key ] = $value[ $field ];

	}



	return $list;

}

10847

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: