Accessing fields in ACF relationship field

Hi, I have an ACF relationship field, which I’m able to display as intended with L&L. From that field, I then want to pull out data within that relationship. What would be the best way to do this?

I imagine checking if the field is true, and then grabbing the ID and then accessing it that way? If anyone has an example of this I would love to take a look.

I’m a few days into L&L and really like it so far! Thank you.

It looks like a loop within a loop is the answer!

This is magic!

2 Likes

Hey Matt, I’ll drop the code I sent you on your Facebook group post here so that you can see a version with preserved indenting:

  <Note>Loop through associated guides</Note>
  <Loop acf_relationship=guide_selection>
    <Note>Map stores key value pairs. Here we use the post ID as the Key, so that we can easily retrieve rates by post ID below</Note>
    <Map name="guide_rates">
        <Note>Loop through the repeater on the guide post, which we can access because we're nested in the guide relationship Loop</Note>
        <Loop acf_repeater=guide_trip_rates>
          <Note>We're going to set our key inside another relationship loop, so we have to store the rate in a variable and pass it in. This also means that we can associate one rate with multiple Trip Builders and it will still work as intended.</Note>
          <Set rate><Field rate /></Set>
            <Loop acf_relationship=trip_selection>
              <Note>Finally setting the key within the guide_rates Map</Note>
              <Key name="{Field id}"><Get rate /></Key>
            </Loop>
        </Loop>
    </Map>
  </Loop>

  <Note>Loop through the associated Trip Builder posts</Note>
  <Loop acf_relationship=trip_selection>
    <Note>Referencing our map name, we pass the post id as the name, and that returns the rate we stored in association with the post ID</Note>
    <li><Field title />: USD $<Field name="{Field id /}" map="guide_rates" /></li>
  </Loop>
  <Loop acf_relationship=guide_selection>
    <Map name="guide_rates">
        <Loop acf_repeater=guide_trip_rates>
          <Set rate><Field rate /></Set>
            <Loop acf_relationship=trip_selection>
              <Key name="{Field id}"><Get rate /></Key>
            </Loop>
        </Loop>
    </Map>
  </Loop>
  
  <Loop acf_relationship=trip_selection>
    <li><Field title />: USD $<Field name="{Field id /}" map="guide_rates" /></li>
  </Loop>
1 Like