Reputation: 167
I have the following code inserted a page using a php code plugin. The plugin's been working well for over a year, and this ONE function from WP doesn't seem to return anything. I've tried using print_r to show me all the properties in the object, but it's empty, with no errors. Any ideas where I'm going wrong? Please let me know if you need more information before down-voting me.
Here's the code:
$user = get_user_by( 'ID', '7' );
echo "Submitted by $user->display_name";
Upvotes: 2
Views: 8745
Reputation: 208
Since 4.4.0 Added 'ID' as an alias of 'id' for the $field
parameter.
Upvotes: 3
Reputation: 4052
Yes, the first parameter has to be lowercase, not uppercase!
$user = get_user_by( 'id', '7' );
echo "Submitted by $user->display_name";
If that doesn't work, go into your admin area and look under Users to make sure you have a user with the id of 7.
Upvotes: 7