I want to access some private messages using entity_load() but I don't know what the entity ID is to call them by. I have the message ID (mid) but that doesn't appear to work.

I'm attempting to load an individual message like this:

      $message_entity = entity_load('privatemsg_message', array($row['mid']));

And this is how Private Message declares hook_entity_property_info().

 * Implements hook_entity_property_info().
function privatemsg_entity_property_info() {
  $info = array();
  // Add meta-data about the basic node properties.
  $properties = &$info['privatemsg_message']['properties'];
  $properties = array(
    'mid' => array(
      'type'  => 'integer',
      'label' => t('Private message ID'),
      'description' => t('Private message ID'),
    'thread_id' => array(
      'type'  => 'integer',
      'label' => t('Private message thread ID'),
      'description' => t('Private message thread ID'),
      'getter callback' => 'entity_property_verbatim_get',
    'author' => array(
      'type'  => 'user',
      'label' => t('Private message author'),
      'description' => t('Private message author'),
      'setter callback' => 'entity_property_verbatim_set',
    'subject' => array(
      'type'  => 'text',
      'label' => t('Private message subject'),
      'description' => t('Private message subject'),
      'setter callback' => 'entity_property_verbatim_set',
    'body' => array(
      'type'  => 'text',
      'label' => t('Private message body'),
      'description' => t('Private message body'),
      'setter callback' => 'entity_property_verbatim_set',
    'timestamp' => array(
      'type' => 'date',
      'label' => t('Private message sent date'),
      'description' => t('Private message sent date'),
  return $info;

How do I get the entity ID for private messages? Is that different than the message ID (mid) or thread ID (thread_id)?

  • 1
    If I recall correctly, message id is mid.
    – No Sssweat
    Commented Dec 20, 2015 at 4:23
  • try $message_entity = entity_load('privatemsg_message', array('mid'));
    – No Sssweat
    Commented Dec 20, 2015 at 4:33

1 Answer 1


It turns out mid is correct, but for whatever reason $row['mid'] was returning a string, not an int. Type-casting the string as an int solved the problem.

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.