Custom fields and field groups are saved as a post, so you can get it using WordPress’ functions. Maybe something like this:
$field_object = get_field_object('custom_field_name');
$field_group_id = wp_get_post_parent_id( $field_object['ID'] );
$field_group = get_post($field_group_id);
I hope this helps.
Not sure I asked the question right. The first step in the process it to create a Field Groups Title. Then you create individual field Labels within the Field Groups.
I’m not interested in the label names but rather the Field Groups Title. It would seem like I could take the post ID and echo the Field Groups Title. Right now in most cases my Field Groups Title is the same as what I hard could into my templates. It would be nice to pull the post id to dynamically create the title that display in the front end.
In this example the Field Group Title is Apprenticeship On Demand and the post id is 263 (visible in the url)
When I put the code for the ACF into a page section the title is always hard coded but I would rather make the section title dynamic to the Field Group Title.
It would also be useful to dynamically pull the Label from the Fields within the Group. In this example the Field Labels are Description and Image.
Is it possible to pull the Title of the Field Group and the Labels from within the Field Group?
Could you please tell me which ACF version did you use? I’ve just found out that the code I gave you doesn’t work on ACF free version. I’m afraid you need to get it manually from the database.
If you use the PRO version, I believe the code does what you asked for. It will get the ID of a custom field and use it to get the object of the field group. With that object, you can get field group title.
Regarding the label, I believe you can do it by using the get_field_object() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_field_object/.
I hope this makes sense 🙂
The topic ‘Field Group’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!