0

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

candidates

  • Name
  • Pic
  • Bio

answers

  • relatedQuestion
  • Body
  • relatedCandidate

questions

  • title
  • body

candidateGroup

  • 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',
    category,
    relatedAnswers
  ) %}
  {% 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>
            <div class="question__candidates__card__header__title">
              <h4><a href="{{ relatedCandidate.url }}">{{ relatedCandidate.title }}</a></h4>
              <p>
                {% set categoryCandidate = relatedCandidate.group.group('candidateGroup').first() %}
                {{ categoryCandidate.title }}
              </p>
            </div>
          </div>
          <div class="question__candidates__card__content">
            {{ answerEntry.body }}
          </div>
        </div>
      {% else %}
        <div class="slate blank">
          There are no answers from candidates in this group yet.
        </div>
      {% endfor %}
    </div>
  {% endfor %}
</div>

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 Mar 5 '15 at 20:03
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.

|improve this answer|||||
  • Yep. You're right. That was it. Going to be a pain updating these entries again but at least I caught it early. – Dennis Eusebio Mar 4 '15 at 11:55
  • Although, I did this and started to re-enter in the relations and it happened again :( – Dennis Eusebio Mar 4 '15 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 Mar 4 '15 at 14:06

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.