I try go get entries (of channel B) related to an entry (of channel A) within a list of entries (of channel A). All entries of channel B have a relationship field and at least one relation to an entry in channel A. But I get no results from channel B.

{% set entries = craft.entries.section('candidates').order('postDate asc') %}
{% for entry in entries %}
    {% set feedbacks = craft.entries.section('candidates_feedbacks').relatedTo(entry.id) %}
    {{ entry.title }}
    {% for feedback in feedbacks %}
        {{ feedback.title }}
    {% endfor %}
{% endfor %}

What am I doing wrong?

Thank you very much for your feedback.

  • Hmmm, I've just created sections with the same names in Craft and related entries like you are, and your code is working perfectly fine for me. I'd double check everything is set up correctly in Craft, because that piece of code seems very straightforward. – Jamie Wade Mar 26 '15 at 13:36
  • Yes, it looks just fine. – carlcs Mar 26 '15 at 13:38
  • I'd start by {{ entries|length }} and {{ feedbacks|length }} just to make sure you're getting the results back you're expecting to get back. – Brad Bell Mar 26 '15 at 15:58

Thank you very much for your support. The code shown in the question is correct.

I have replaced the relationship field - and now it works perfect. The problem could have been that I defined the field first as a number field an then changed to a relationship field - but this is just speculation.

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.