timber: Repeater within Relationship returning String instead of Array

Expected behavior

I have a relationship field pulling in a repeater of images and expect them to display.

Actual behavior

If I print_r I only get the count of how many images there are printed. A dump returns:

string(1) “4”

I tried setting the repeater field to return Array, URL and ID on the image field and they all produce the same result. I know I’ve done this in past versions of Timber, so I’m wondering if something has shifted in how I need to get these field values?

Steps to reproduce behavior

PHP file:

$context['featured_case_studies'] = get_field('featured_case_studies');

Twig file:

{% for study in featured_case_studies %} {% set study = TimberPost(study) %} <div class="case-study-entry" id="study-0{{loop.index}}"> <div class="study-title"> <span>Case Study</span> <h4>{{study.title}}</h4> <h3 class="location">{{study.location}}</h3> <a href="" class="view-photos"><img src="{{site.theme.link}}/assets/img/view-photos.gif" alt=""></a> <div id="" class="project-photos"> {{ dump(study.project_photos) }} {% for photo in study.project_photos %} <a href="" rel="study-0{{loop.index}}" class="fancybox"><img src="{{TimberImage(photo.project_image).src|resize(1200,9999,'center')}}" alt=""></a> {% endfor %} </div> </div> </div> {% endfor %}

(Not sure why my code won’t format properly, sorry for that. Spacing it out only made it worse).

What version of WordPress, PHP and Timber are you using?

WP 4.5.2 and Timber 10.0.1

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

Downloaded from wp.org

UPDATE

I did roll back Timber and got the same behavior.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 25 (4 by maintainers)

Most upvoted comments

I realized the issue. Notice the width and height resize arguments I was passing. I confused TimberImage’s resize with WP’s default, where you normally pass 9999 as the “infinite height” attribute. TimberImage doesn’t apparently need this, so I was just choking it, apparently, as it tried to resize all the images into some crazy height.

So…user error. Don’t hate me! 😃

But, while you’re here, Jared…notice @connorjburton comment above about not needing

{% set study = TimberPost(study) %}

If I remove this, all my fields disappear. Would love some clarity around this…

Jared,

SO appreciate your time and help. New progress: I can get this code to output the markup:

        <div class="case-studies">
          {% for study in featured_case_studies %}
            {% set study = TimberPost(study) %}
              <div class="case-study-entry" id="study-0{{loop.index}}">
                <div class="study-title">
                  <span>Case Study</span>
                  <h4>{{study.title}}</h4>
                  <h3 class="location">{{study.location}}</h3>
                  <a href="" class="view-photos"><img src="{{site.theme.link}}/assets/img/view-photos.gif" alt=""></a>
                  <div id="" class="project-photos">
                    {% for photo in study.get_field('project_photos') %}
                      <a href="" rel="study-{{study.location|lower}}" class="fancybox"><img src="{{TimberImage(study.photo.project_image).src|resize(1200,9999,'center')}}" alt=""></a>
                    {% endfor %}
                  </div>
                </div>
                <div class="study-info">
                  <div class="challenge"><span class="study-header">Challenge:</span> {{study.challenge}}</div>
                  <div class="solution"><span class="study-header">Solution:</span> {{study.solution}}</div>
                  <div class="results"><span class="study-header">Results:</span> {{study.results}}</div>
                  <div class="contractor"><span class="study-header">Contractor:</span> {{study.contractor}}</div>
                </div>
              </div>
            {% endfor %}
          </div>

And the page loads and the items are ouput with the proper markup (but the image source is clearly not going to work) and the image source is empty. If I change the image to this to get the actual url:

<img src="{{TimberImage(photo.project_image).src|resize(1200,9999,'center')}}" alt="">

…it locks up.

Attached is the JSON file.

Also in Timber 1.0.0 you don’t have to manually set set study = TimberPost, we automatically look for posts in ACF repeater fields and return them as TimberPost

Don’t you have to do study.get_field('project_photos') - can’t remember off by heart but try that