7

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?

10

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 }}
0
2

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

0

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.