Support » Plugin: Custom Content Shortcode » How can I display a specific layout from an ACF Flexible Content field?

  • Hi – hope you can help with this.

    I have a query about how I can pull through a specific layout from an ACF Flexible Content field.

    I’m creating a simple office directory for different countries. I have a Custom Post Type of countries and then the following ACF setup on my CPT:

    Offices [Flexible Content]
    ⮑ Office Name [Text]
    ⮑ Phone [Repeater]
    ⮑ Team [Flexible Content]
    ⮑ Team Name [Text]
    ⮑ Team Members [Repeater] (with sub fields of Role and Name)

    So from the CPT in wp-admin you can create multiple offices for a country (defined as layouts within ACF). Each office may have multiple teams.

    So for example, France may have three offices – which have multiple teams each respectively. Whereas, Germany may only have one office that has one team.

    On the front end I want to display this data which I’ve been attempting to do via shortcodes. But I need to be able to display the offices individually. So for example, [display the different ACF fields that relate to Office #1]

    My issue is that when I use [flex offices …] it returns all the offices and I don’t know how to specify just one of them.

    My current shortcode content is as follows:

    [flex offices]

    [layout officedetails]
    [field officename]

    [repeater phone]
    [field phonetype]: [field phonenumber]
    [/repeater]

    [-flex people]
    [-layout peopledetails]
    [field teamname]
    [-repeater teammembers]
    [field role]: [field name]
    [/-repeater]
    [/-layout]
    [/-flex]

    [/layout]

    [/flex]

    So how can I adapt this to only display Office #1 or Office #2 for example?

    Thanks so much for your time.
    James

    (Using all latest versions: WordPress 5.7, ACF Pro 5.9.5, CPT UI 1.8.2, CPT UI Extended 1.6.0)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try a combination of pass list and if.

    I use this for repeater fields. Depending on the fields this approach enables a very granular listing.

    Example: Listing only German and UK offices:

    [pass list='de,uk']
    [repeater whatever]
    [if field=country value='{ITEM}']
    Do whatever you want with the content
    [/if]
    [/repeater]
    [/pass]
    Thread Starter jamesburden

    (@jamesburden)

    Thanks so much – really appreciate the quick response. I’ve been experimenting with this and trying to get my head round pass list but not sure I quite understand it. Is there any further information available on how to use this? I’ve also been looking on the information / help pages within the plugin settings. But any further light you can shed on it would be very helpful.

    Its like an array of vars.

    A loop is performed and each list item is passed to {ITEM}

    You can pass multiple items with list like that: (Multi Dimension array)

    list=’car:red,car:green,bik:silver’

    No you access the list-items (f.e. car:red) with {ITEM_1} = car and {ITEM_2} = red

    I use this pretty often to create ordered-lists.

    Thread Starter jamesburden

    (@jamesburden)

    Thanks so much – that’s really helpful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.