I have a content type of 'partners', and I wanted to create a body text like 'Currently we are working with X partners'. I have token-filter working, but I cannot find a token that allows me to choose the content-type.

[content-type:node-count] Doesn't do anything.

[node:content-type:node-count] Returns the amount of the current type (basic page, not partner).

Is there some token that allows me to choose the content-type to work with? eg. something like [content-type:?:node-count] where I can enter my content-type of partner on the ? ?


I ended up creating a custom module for this to calculate the specific amount of items. Now I can use a token like [partner:partners].

 * Implements hook_token_info().
function partner_token_token_info() {
  $types['partner'] = array(
    'name' => t("Partner Tokens"),
    'description' => t("Tokens for partners."),

  $partner['partners'] = array(
    'name' => t("Partners"),
    'description' => t("The count of partners."),

  return array(
    'types' => $types,
    'tokens' => array(
      'partner' => $partner,

 * Implements hook_tokens().
function partner_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  if ($type == 'partner') {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'partners':

          $query = db_select('node', 'n')
            ->condition('type', 'partner');
          $num_rows = $query->countQuery()->execute()->fetchField();

          $replacements[$original] = $num_rows;

  return $replacements;

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.