I'm making a block to be displayed on a node page that I want to display some information about the author of the node. I need to be able to show the number nodes of different types that the author has created. Any suggestions? I found this which gets me halfway there, but I need to be able to filter it by only the node authors content.

1 Answer 1


The simplest way would be to extend the query from the other question you linked to and add the user id as an extra parameter:

function yourtheme_get_node_count($content_type) {
  $query = "
    FROM {node} n
    WHERE n.type = :type
    AND n.uid = :uid";

  // Get the node object for the current page.
  $node = menu_get_object();

  $params = array(':type' => $content_type, ':uid' => $node->uid);
  $amount = db_query($query, $params)->fetchField();

  return $amount;

Be sure to only call this on a node page as menu_get_object() will only return a node object when you're on such a page.


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.