How can I get the count of all the inbox messages, with the Private message module?

Below the inbox messages, I need to display the count of total messages, such as:

10 of 55

_privatemsg_get_new_messages() is the function to get new messages in Drupal 5.

Is there any function to get the count of all messages in Drupal 6?


There is a privatemsg_unread_count() function in Drupal 7. If that doesn't work in Drupal 6, check the module file for the name of the function.

  • Its in D6 too. But it provides only the count of unread messages. I need the count of ALL messages (total of which is read and which is unread). – Fero Nov 21 '11 at 3:32

This code is used to get the list of all the messages in the inbox.

global $user;
$query = _privatemsg_assemble_query('list', $user, 'inbox');
$total_count = db_result(db_query($query['count'])); 
echo $total_count;

This Should Work:

$query = db_select('pm_index', 'pmi');

        ->fields('pmi', array('thread_id'))
        ->condition('pmi.deleted', 0)
        ->condition('pmi.recipient', $account->uid)
        ->condition('pmi.type', array('hidden', 'user'));
$results = $query->execute()->rowCount();
return $results;
print privatemsg_unread_count($account = NULL);



  • 3
    This answer doesn't add much beyond what another user gave, and which the OP said didn't work. Should this call work to get the count of all messages, and not just unread ones? – mpdonadio Dec 4 '12 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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