I don’t use ACF so I hope I’m not leading you astray, but I don’t think there’s actually a parameter to display the slug. Still, you could do it using the pass shortcode:
[pass field="field_slug_here"]
<h1 id="{FIELD}">[sub field="mpg_section_title"]</h1>
[/pass]
Something along those lines should work… I hope this helps!
What type of field are you trying to display, like a radio/select/checkbox – something that returns a slug or label as value? You can try the general parameter out="slug", but it depends if it’s supported or not.
I’m currently working on an update of all plugin modules, and plan to improve the ACF shortcodes also. I’ll make a note to look at displaying value slugs for suitable field types.
Hmmm, I realise my question was not very clear, sorry about that.
I have a ‘text’ field and want retrieve its name (slug).
E.g. If field name (slug) is “mpg_section_title”, I would like to use this value.
Hope this is clearer?
I see, the field slug, not the slug of its value. Hmm..how are you getting the field label to display?
To be honest, I haven’t worked with the flexible content field in some time, so I had to set up a test page to fully explore what is possible and what is not.
From what I see, it seems the label and slug of the field value is possible to display, but not slug of the field itself. Since you’re manually specifying it for [sub], couldn’t you do the same for <a id="..">? Or is there a reason it needs to be dynamically generated?
Within the flexible content field I have a layout field (called Section) which has two sub fields; a text field (Section Header) and a WYSIWYG field (section Content). This Section field can be repeated any number of times when adding content to the backend. I need to dynamically generate an id for the Section Header field so the the in-page navigation works.
Here’s the code I am using…
[flex field="page_layout"]
[layout name="section"]
<h1 id="[section_header_field_slug_needed_here]">[sub field="section_header"]</h1>
[sub field="section_content"]
[/layout]
[/flex]
With the latest update, you can generate unique IDs like this:
<h1 id="section_header_{COUNT}">
So, the each header will have IDs like section_header_1, section_header_2 and so on. Not exactly what you were asking for (field slugs), but I think that will achieve what you need?
Thank you, yes your suggestion will work just fine. Once again your generous help is very much appreciated.
Whoops forgot to mark this as resolved.
Great, I’m glad it worked. 🙂