Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using this in the root of a structure to try and get the count of entries in another part of the structure.

{% set count = craft.entries.section('hotelDetails').descendantOf('oakview-hotel').level(3).type('review').total() %}
        {{ count }}

But it's including entries from other hotels, I hoped descendantOf('oakview-hotel') would restrict the count to only oakview-hotel. When I replace escendantOf('oakview-hotel') with descendantOf(17) 17 being the ID oakview-hotel the count is restricted to oakview-hotel and the entry count is correct.

Ca anyone please telly me why descendantOf('oakview-hotel') isn't working for me or suggest a better way to do this?

share|improve this question
up vote 6 down vote accepted

There may be a better option, but off the top of my head, you could do:

{% set countParent = craft.entries.slug('oakview-hotel').first() %}
{% set count = craft.entries.section('hotelDetails').descendantOf(countParent).level(3).type('review').total() %}
        {{ count }}
share|improve this answer
Thanks Steve! I can see where I was going wrong now. – user1070143 Jul 21 '14 at 15:29

descendantOf accepts either an EntryModel object or an entry’s ID. And you are passing it a string that isn't the id, so that's why it isn't working

share|improve this answer
Thanks for the explanation Marion. – user1070143 Jul 21 '14 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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