Skip to content

Instantly share code, notes, and snippets.

@wpsmith wpsmith/wp_list_pluck.php Secret

Last active Oct 6, 2015
Embed
What would you like to do?
PHP: WordPress wp_list_pluck error
<?php
// Create objects
$obj1 = $obj2 = new stdClass();
$obj1->slug = 'slug-1';
$obj1->name = 'Slug 1';
$obj2->slug = 'slug-2';
$obj2->name = 'Slug 2';
// Create array
$array_of_objects = array( $obj1, $obj2 );
// Test
$list = wp_list_pluck( $array_of_objects, 'ID' );
// Alternate
if ( $list = wp_list_pluck( $array_of_objects, 'ID' ) ) {
//do something
}
/*
Result:
Notice: Undefined property: stdClass::$ID in /srv/www/trunk/htdocs/wp-includes/functions.php on line 3209
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.