Pro and ACF - selecting a CPT via a relationship field and then outputting flexible content

Hi -

To be clear - when I’m referring to ‘menus’ here, I mean the kind you look at in a restaurant to order your food - not Wordpress menus!

I have a site I’m building for a small cafe and I’d like for them to be able to create various “food menus” using a flexible content field within a custom post type of ‘food_menus’. Then they can choose which “food menu” appears on their /menus page by selecting the appropriate one via a relationship field. I then want to be able to output this “Food Menu” via a Looper Provider and Consumer onto a series of rows so that each sub-item from the flexible content field creates a new row.

The Looper Provider, I have setup as Dynamic Content using the input:

{{dc:acf:post_field field=“lunch_menu”}}

This works in so much as I can output the price from the first flexible content row, albeit via the Dynamic Content Post Meta key:

£ {{dc:post:meta key=“food_menu_0_price”}}

This is the £4.50 you see in the above screenshot.

I could also output the first menu item using:

{{dc:post:meta key=“food_menu_0_menu_item”}}

Which would give me this:

Screenshot 2021-09-15 at 22.45.44

However, I would like to be able to output the sub field of the flexible content item, and via the Loopers, I can’t see how this is possible. Surely if I can access the meta info, I can access the flexible content field and in turn the sub-field etc.

I think I’m close, but I can’t seem to find the correct syntax to get hold of the sub-field.

Thank you

Geoff

Also - using this page as an example: https://theme.co/docs/acf-pro-and-loopers I have tried setting up the column as the Looper Provider and Consumer using Dynamic Content with the input:

{{dc:acf:post_field field=“lunch_menu”}}

Then I setup the row to once again be the nested Provider and Consumer using the input:

{{dc:looper:field key=“food_menu”}}

… and finally I setup the text field within the row as a Looper Consumer using the input:

{{dc:looper:field key=“menu_item”}}

However, I still can’t get hold of that sub-field data and display it.

Hello @geoffmartyn,

Thank you for the very detailed post information. You just have misplaced the loopers which is why you are having the issue. You need the Row 1 element as your Looper Provider while the Column 1 should be your Looper Consumer.

You will have to use the Query Builder in your Looper Provider to display all your Food Menus:

And then, you can nest another Looper Provider inside the column consumer which will then display the Food menu items. This second Looper provider will be the one to use the Dynamic Content.

Please the secure note for the URL of the test page I made for you.

Kindly let us know how it goes.

Hi Rue,

Thank you so much for explaining and providing clarity on how this works. I have it now - first class support as ever.

:star_struck:

Kind regards,

Geoff

We are delighted to assist you with this.

Cheers!

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