So I have these sections and fields that I'm dealing with:


  • Name
  • Pic
  • Bio


  • relatedQuestion
  • Body
  • relatedCandidate


  • title
  • body


  • title

I'm outputting a single page using the question:

Question and Info

Candidate Group Name

  • Candidate

    • Answer
  • Candidate

    • Answer

... Repeats ...

So my current setup looks like this:

{# Get the answers that are related to the question entry #}
{% set relatedAnswers = craft.entries.section('answers').relatedTo(entry) %}

{# Loop through categories #}
{% for category in craft.categories.group('candidateGroup') %}

  {{ category.title }}

  {# Get me the candidates that belong to this category and have an answer related to this question entry #}
  {% set candidateAnswers = craft.entries.section('candidates').relatedTo('and',
  ) %}
  {% for candidateAnswer in candidateAnswers %}

    {# Output the candidate's info and their answer #}

  {% endfor %}
{% endfor %}

I feel like this is right and it seems to be working locally but when I get it live on the site it's having issues recognizing what "entry" it's a part of. No matter what entry I go to via url, it outputs the same answers.

I tried to do a simple loop to see what relatedAnswers outputs, and it's the right information. It's just getting lost in that inner loop somehow.

Update: I believe it is working locally just fine. But for some reason, on my Media Temple hosted site, it's not outputting in the same manner. I double and triple checked all the fields and couldn't find any differences?

Update 2: I can't figure this out for the life of me. It works fine on local, just not on production. I checked the database to see if there anything out of the ordinary and it looked fine to me. I installed the introvert plugin to see if the relations were working properly and they seem to be just fine. Kind of lost at this point.

Updated 3 I tried it another way:

<div class="question__candidates">
  {% for category in craft.categories.group('candidateGroup') %}
    <div class="question__row">
      <h3>{{ category.title }}</h3>
      {% for answerEntry in craft.entries.section('answers').relatedTo('and',category,entry) %}
        <div class="question__candidates__card">
          <div class="question__candidates__card__header">
            <div class="question__candidates__card__header__avatar">
              {% set relatedCandidate = craft.entries.section('candidates').relatedTo(answerEntry).first() %}
              {% set asset = relatedCandidate.avatar.first() %}
              <a href="{{ relatedCandidate.url }}"><img src="{{ asset.url }}" /></a>
            <div class="question__candidates__card__header__title">
              <h4><a href="{{ relatedCandidate.url }}">{{ relatedCandidate.title }}</a></h4>
                {% set categoryCandidate = relatedCandidate.group.group('candidateGroup').first() %}
                {{ categoryCandidate.title }}
          <div class="question__candidates__card__content">
            {{ answerEntry.body }}
      {% else %}
        <div class="slate blank">
          There are no answers from candidates in this group yet.
      {% endfor %}
  {% endfor %}

Unlike the other solution, my problem on the server is that it doesn't return any entries at all. I'm assuming it has something to do with that 'relatedTo(entry)'. It's like it doesn't recognize that at all. In the first case it just ignores it and in this case it's like it can't read it.

  • I've responded to both of your support tickets... are you not getting them?
    – Brad Bell
    Commented Mar 5, 2015 at 20:03

1 Answer 1


There could be corrupt data in your remote database. I tried to answer a similar case some weeks ago: "Entries related to Users", where the code was right, but Craft returned the wrong entries.

I'd check if it helps to clear the database and do a fresh import from you local environment.

  • Yep. You're right. That was it. Going to be a pain updating these entries again but at least I caught it early. Commented Mar 4, 2015 at 11:55
  • Although, I did this and started to re-enter in the relations and it happened again :( Commented Mar 4, 2015 at 14:02
  • Ohh no, @Dennis. I'm really sorry for you! :( ...best thing you can probably do now is to contact P&T support.
    – carlcs
    Commented Mar 4, 2015 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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