ACF Pro select field key to display value

Howdy!

I’ve have been able to populate an ACF Pro select field with custom post types. For every choice it has the permalink as a value and the post title as the label. (permalink : post title). So far, so good. Now I would like to display the label as a button text and the permalink as the button’s link.

The select field’s output is set to Both (array). The label I can successfully display with {{dc:acf:post_field_setting field="FIELD_NAME" key="value.label"}} . I actually found this on this very forum. Now I’m trying to get the value (the permalink in this case). I have already tried many different keys and have not been able to find the right one by guessing or searching the internet. I’m hoping you can help me to get the value.

Hey @eyedia,

Thanks for reaching out!

In order to help you with your concerns, we need to check your backend settings. To do that, please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • Page URL or Layout Builder name

You can find the Secure Note button at the bottom of your posts.

Thank you.

Thank for getting back to me this fast! I will attach the details to this post.

Hey @eyedia,

I check your setup but I am not quite sure which page you are working on. Just want to let you know that it will take at least 3 Looper provider to access the array. One good example is on this thread.

Can you please elaborate more.

Thank you.

Howdy!

With help from the post that you referenced and ACF documentation I have figured out how to do this and decided to share it with the themeco community. As a bonus I will include an example of how to apply it to the ACF Google Maps too.

So the following is to display elements from an array being output by ACF (Advanced Custom Fields).

Regular page structure:

  1. First layer (e.g. section)
    1.1. Looper Provider -> Dynamic Content -> Query Builder -> POST_TYPE
    1.2. Looper Consumer
  2. Second layer (e.g. row)
    2.1. Looper Provider -> Dynamic Content -> ACF key (e.g. my_select_field)
    2.2. Looper Consumer
  3. Third layer (e.g. column)
    3.1 Looper Provider -> Dynamic Content -> Looper current item
  4. Fourth layer (e.g. div)
    4.1. Looper Consumer
    4.2. Element with dynamic content* (e.g. text). Use Looper field key.

Single or archive (layouts) structure:
Because these pages are already pulling in a post type through the page condition settings the first layer is redundant.

  1. First layer (e.g. row)
    1.1. Looper Provider -> Dynamic Content -> ACF key
    1.2. Looper Consumer
  2. Second layer (e.g. column)
    2.1 Looper Provider -> Dynamic Content -> Looper current item
  3. Third layer (e.g. div)
    3.1. Looper Consumer
    3.2. Element with dynamic content* (e.g. text). Use Looper field key.

*This will works with several ACF fields that output an array. With a select field for example you can use {{dc:looper:field key="label"}} and {{dc:looper:field key="value"}} to display the label and value respectively. The ACF Google Maps is another one that outputs an array and works the same way. The keys are as follows:

  • Complete address:
    {{dc:looper:field key="address"}}
  • Street + house number:
    {{dc:looper:field key="name"}}
  • Street:
    {{dc:looper:field key="street_name"}}
  • Street (short):
    {{dc:looper:field key="street_name_short"}}
  • House number:
    {{dc:looper:field key="street_number"}}
  • City:
    {{dc:looper:field key="city"}}
  • State/province:
    {{dc:looper:field key="state"}}
  • Zip/postal code:
    {{dc:looper:field key="post_code"}}
  • Country:
    {{dc:looper:field key="country"}}
  • Country (short):
    {{dc:looper:field key="country_short"}}
  • Google Maps ID:
    {{dc:looper:field key="place_id"}}
  • Longitude:
    {{dc:looper:field key="lng"}}
  • Latitude:
    {{dc:looper:field key="lat"}}

Above is confirmed to work in my test environment and hopefully @marc_a can confirm if this is the right way to go.

Hey @eyedia,

Yes, your implementation is correct in getting the key value and thank you for sharing your idea, we really appreciate it

Thank you.

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