I'm not able to understand what is the code I should use to verify if user has (or not) a profile (made by profile2 module) associated.

I use profile2_load_by_user($uid, "my-profile-name") and it always returns me a "Profile" object... also for users that has not that profile (for example users listed in /admin/people/noprofile).

I know I can test if some mandatory field is currently filled, but do you know what is the "formally correct" way to proceed?


2 Answers 2


If you are doing profile2_load_by_user and profile object is showing, then its profile object has been created. If Profile object has not been created for a user, then its profile object will be empty, means its pid has still not been created.

You can check for the same, in your database, inside profile table.

  • Yes, you're rigth: there is a corresponding row inside profile table (with the same pid/uid of the Profile object returned by profile2_load_by_user)... but I can't figure why /admin/people/noprofile page (labelled as "Sites users without profile") reports me that user. Mar 24, 2016 at 17:49
  • Ignore my previous comment (URL I reported was a view that filters on a mandatory field). Thank you for explaining. Mar 25, 2016 at 8:45

Try to check what return

$profiles = profile2_load_multiple(FALSE, array('uid' => $uid));

or direct query
$result = db_select('profile', 'p')
      ->fields('p', array('type', 'pid'))
      ->condition('uid', $uid)

  • I made a query to DB, but I think it is the same... as I wrote as comment in the other answer: a profile exists in that row, but... then... why that user is reported as "Sites users without profile" in /admin/people/noprofile page? Mar 24, 2016 at 17:50
  • 1
    How did you get that page? I don't see code related to /admin/people/noprofile in Profile 2 module
    – smile
    Mar 24, 2016 at 17:54
  • Me too... and there is no any track of the string "noprofile" inside aliases on in my drupal installation folder... I'm investigating to understand what's happening, but I suppose it can be a kind of configuration made by old developers of the platform. I will update you. Thank you for now. Mar 24, 2016 at 18:00
  • Yes, it was as I supposed... it was a specific view that filters on mandatory fields. BTW sorry, but I'll choose the other answer as accepted, just because it explains in the main "box" what is the core of my question, and can be better for future readers. +1 and thank you for your support. Mar 25, 2016 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.