ACF Pro Relationship Field Not Displaying

Hi,

I am trying to use dynamic data from ACF Pro in a Single Layout and the field type Relationship is not showing in the preview and two other fields which do show in the preview do not show on the front end.

What am trying to achieve is as follows. I have two Post Categories - Memorials and Casualties, each of which has an ACF Pro field group.

Memorials has the following fields:
Location (Text)
Town (Text)
Casualties (Relationship - relationship to the Post category = Casualties). This field can have multiple results.

Casualties
Name (Text)
Rank (Text)
Memorial (Relationship - relationship to Post category = Memorials). This will display a single memorial

When creating a new post for either Memorials or Casualties, I see the correct ACF Pro fields and can select the expected data from the relationship fields.

In Cornerstone I have a simple Section > Row > Column set up with three text elements in the column. Each text element uses dynamic data in the format {{dc:acf:post_field field="name"}} (with the ACF Pro field as the field name.

In the Memorials Single Layout preview I can see the ACF fields Name and Rank, but the relationship field displays nothing. On the front end there is nothing at all showing for the individual posts.

Any help is gratefully received. Details in a Secure Note.

Thanks,
Christopher

Hey @whitemedia,

Thanks for reaching out!

You need another Looper provider to access the ACF relationship. A good example is on these thread.

Hope that helps.

HI @marc_a,

Thank you for your reply. The links are helpful, but I am not quite sure where the Looper Providers should be located. In my examples, I am using the simple structure of Section > Row > Column > Text Elements.

Currently I have the Looper Provider as a Query Builder and a Looper Consumer in the Column.

I would be grateful if you could describe what should be where in more detail.

Many thanks,
Christopher

Any further help guys? @charlie maybe :grinning:

So for something like this, you are going to want to put the acf field as the provider with a type of Dynamic Content. The consumer (the text) in this case is then a consumer inside this. See secure note.

Another helpful hint, if you aren’t seeing any data in your dynamic content. If you do type="json" in your Dynamic Content you’ll receive anything that is an array as JSON. Using an array in a text field will not display anything and can be a little confusing when it happens. If you want to hide this section because there is not data, you would use this same thing in the condition.

image

Thanks for the guidance @charlie. It is beginning to make sense, but I cannot seem to get the looper working correctly. Either the relationship ACF field shows just one (rather than all) entry and / or the same results are shown for different posts.

I have made one change since you last looked in and rather than using post and category, I have created two new post types - memorial and casualty.

This is the structure for the looper:

2023-01-24_12-05-06

At Column level, I have the looper provider set as follows with the looper consumer set to “One”, as only the data for the individual post is needed (this is a Single layout):

2023-01-24_12-03-21

Within the text elements we have the appropriate ACF field referenced {{dc:acf:post_field field="memorial"}}

Next we have a div which has the following looper provider, as you set it up:

2023-01-24_12-07-52

Finally, within the div is another text element which should display the multiple results from the ACF relationship field. The text field has the following content in it: {{dc:post:title}} {{dc:acf:post_field field="casualties_listed"}} and the text field’s looper consumer is turned on:

2023-01-24_12-10-24

Please see the secure note for more.

Thanks,
Christopher

Hey @whitemedia,

Since this is a single layout, you don’t need to add Looper Provider in your column 1 because the single layout page was already assigned to Memorial post type and it will automatically loop the data on that post type. That being said, I disable the Looper Provider and Looper Consumer in your column 1 then it is now showing the correct data in the frontend.

Hillesley
Backend:


Frontend:

lasborough
Backend:


Frontend:

Hope that helps.

Thank you @marc_a,

That is working perfectly and I have replicated it on the casualties single as well. Loopers take a bit of “getting to know”!

One final question I have is, how can I make the links in the text element, which sits within the <div> a hyperlink? The standard text hyperlinking will not accept dynamic code as it always appends http:// and there does not appear to be a Link setting for the text element. Is it possible to make each entry in the relationship text hyperlinked?

Thanks,
Christopher

Hey Christopher,

You could try adding a div and inside the div add a text element.

In the div element change the HTML tag to <a>. This will make the text like an anchor.

Hope that helps.

Hi @marc_a,

Thanks for the guidance. A slight tweak did what I wanted. I have added a div within the div.

2023-01-25_17-07-45

div 1 is set to <div> and has the looper provider with dynamic content {{dc:acf:post_field field="casualties_listed"}} as you helped me with earlier.

div 2 is the freshly added div set to <a>. The dynamic content used is {{dc:post:permalink}} and its looper consumer is turned on to All

The text element within div 2 has now had its looper consumer turned off and its contents are {{dc:acf:post_field field="casualty_rank"}} {{dc:post:title}}{{dc:acf:post_field field="casualties_listed"}} to bring in the two ACF fields given by the looper provider in div 1.

Thanks for your help in pointing me in the right direction!
Christopher

Hey Christopher,

You’re welcome!

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.