Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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

2 Answers 2

up vote 4 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 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 at 17:13

Your Answer

 
discard

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.