Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Last active October 6, 2015 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/91b8cab4d258133b32d3 to your computer and use it in GitHub Desktop.
Save wpsmith/91b8cab4d258133b32d3 to your computer and use it in GitHub Desktop.
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