Help getting the values from user profile fields from currently logged in user As the title says, I am trying to get the values from a custom field I added to the user profile. I am using this code from a previously asked question regarding this.

$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());
$value = user-&gt;custom_field-&gt;value;


This seemed to work for the person that previously asked this question but the problem I am running into is that it is only returning values of an anonymous user regardless of who I am logged in as. For example if I replace custom_field with uid it will return a value of '0'. Any idea where I could be going wrong?
You're missing a $ in your second line.. Should be $user-> 

I always use the below.

global $user;
$user = user_load($user-&gt;uid)


And then get the field like your last line. If someone else could confirm if that is a waste and there's a better way to load the field, that'd be great.