Advertisement
DidouS

20221212-JA-get group field from post's author

Dec 12th, 2022 (edited)
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.73 KB | None | 0 0
  1. {#
  2.     get the correct field, but this time from the post's author ID
  3.     we use 'post.author.ID'. For ACF that needs to be formatted to a 'user_[##]' format.
  4.     ~ is the symbol for concatenation in Twig (whereas it's . in PHP)
  5.    
  6. #}
  7. {% set group = tb.get_field( 'user' , 'user_' ~post.author.ID ) %}
  8. {#
  9.     check if the group field has any length at all (if not, no point in trying to display a logo)
  10.     To use 'group' subfields, simply use group.subfieldname
  11. #}
  12. {% if group|length %}
  13.     {% set image = TimberImage( group.imageuser ) %}
  14.     <img src="{{ image.src('large') }}" width="100%" alt="{{ image.alt }}" aria-label="{{ image.title }}" />
  15. {% else %}
  16.     <h5>There is no field value or user not logged in</h5>
  17. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement