0

I was wondering how to get the number of nodes I have, filtered by the node count and status.

For example: how many published articles I have.

I was thinking about using Entity Query to get the node count.

1
  • Keep in mind that questions are closed basing on their content. The fact you are answering your own question doesn't make it immune from being closed.
    – avpaderno
    Commented Oct 12, 2015 at 12:04

1 Answer 1

6

This function will give you the count of the node by its status and content type.

Example: if nodeCountState(1,'article');

the count of number of nodes in the article content type which is published will be displayed.

 public function nodeCountState($status, $type) {
    $query = \Drupal::entityQuery('node')
            ->condition('status', $status)
            ->condition('type', $type);
    $result = $query->count()->execute();
    return $result;
  }

Hope this help some one :)

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