8

Is it possible to return a count of the number of items returned in an entityfieldquery query?

  • do you want to get the result as well as the count? if you just want the count then you could set the query to count. something like $count = $query->count()->execute(); – Mohammed Shameem Jan 18 '13 at 13:30
  • I think that should do it. Do you want to add that as an answer? – Andrew Welch Jan 18 '13 at 13:34
  • I have added as an answer :-) – Mohammed Shameem Jan 18 '13 at 13:35
14

if you just want the count then you could set the query to count.

something like

$count = $query->count()->execute()

See here for more detail

  • 3
    For Drupal 8: $query = \Drupal::entityQuery('node')->condition('type', "article"); echo $query->count()->execute() . "\n"; – RaisinBranCrunch Jan 9 '17 at 19:15
0

If required you might as well try Field Count Formatter It will display the number of item in a multifield

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.