Ad
WordPress ACF Repeaters With Timber/Twig
Looked around the Google a lot but couldn't find the solution. I'm new to Twig/Timber but I have a lot Laravel experience so it's similar but I'm not familiar with how to work with ACF Repeater fields within Twig templating.
I've got my ACF Repeater Field Setup:
Repeater Name: Contact
Within the Repeater I have:
Contact Name: contact_name
Contact E-mail Address: contact_email_address
Contact Phone Number: contact_phone_number
This is what's currently "not working" in my Twig file:
{% if post.contact %}
<h3>Contacts</h3>
{% for contact in post.contact %}
<p><strong>Name:</strong> {{ post.contact_name }}</p>
<p><strong>E-mail:</strong> {{ post.contact_email_address }}</p>
<p><strong>Phone:</strong> {{ post.contact_phone_number }}</p>
{% endfor %}
{% endif %}
But no dice. I know post.contact
is working because it's displaying <h3>Contacts</h3>
. I'm more concerened about the foreach that doesn't seem to be working as intended.
Thanks for any help or guidance.
Update: I looked at the documentation and tried:
{% for contact in post.contact('contact') %}
But that didn't seem to have any effect either.
Ad
Answer
Resolved with:
{% if post.contact %}
<h3>Contacts</h3>
{% for contact in post.meta('contacts') %}
<p><strong>Name:</strong> {{ contact.contact_name }}</p>
<p><strong>E-mail:</strong> {{ contact.contact_email_address }}</p>
<p><strong>Phone:</strong> {{ contact.contact_phone_number }}</p>
{% endfor %}
{% endif %}
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad