-
-
Save wpsmith/91b8cab4d258133b32d3 to your computer and use it in GitHub Desktop.
PHP: WordPress wp_list_pluck error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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