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.

closed as too broad by Mołot, Scott Joudry, Geoff, Krishna Mohan, kiamlaluno Oct 12 '15 at 12:03

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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. – kiamlaluno Oct 12 '15 at 12:04
4

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.