Support » Plugin: Timber » getting images from ACF relationship Field

  • Resolved riikk

    (@riikk)


    Hi,

    i use the the Advanced Custom Field Plugin, and want to show articles using the
    Field Type “Relation”.
    Like shown here:
    http://www.advancedcustomfields.com/resources/field-types/relationship/
    (Basic loop (without setup_postdata),
    and it worked fine in other Projects.

    Now with Timber i have Problems getting the Featured Image of a blog Post. (and the Permalink as well). All the other Stuff like Title, Excerpt, Date works fine.

    here is my Code:

    {% set relations = post.get_field('my-custom-fieldname') %}
         {% for relation in relations %}
    	<div class="span7">
    	     <article class="focus">
    
    		<a href="{{relation.post_link}}" >
    		<h2>{{relation.post_title}}</h2>
    		<p class="intro">{{relation.post_content|excerpt(30)}}...</p>
    
    		<img src="{{relation.post_thumbnail.src}}" alt="" />
    
    		 <p>{{relation.post_date|date('j.d.Y')}}</p>
    		 <p>Article by {{relation.author_name}}</p>
    		 </a>
    
    		</article>
         </div>
    {% endfor %}

    i tried everything i could find regarding images in timber, but without no luck.
    thanks for feedback.
    riikk

    https://wordpress.org/plugins/timber-library/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author jarednova

    (@jarednova)

    Hi riikk, you just need to tell Timber how to interpret the data you get back from ACF, this line should do it….

    {% set relations = TimberPost(post.get_field('my-custom-fieldname')) %}

    The correct syntax for thumbnail is…

    <img src="{{relation.thumbnail.src}}" alt="" />

    (as opposed to post_thumbnail)

    Hi jarednova,

    thanks. that worked.
    in between i had it also working using the function method:

    <p>{{function('get_the_post_thumbnail', post.ID, 'medium' )}}</p>
    Plugin Author jarednova

    (@jarednova)

    Great to hear!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘getting images from ACF relationship Field’ is closed to new replies.