Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

ACF: How to get the full field name (meta_key) by a field key?

There’s a few ways to achieve this but here’s one which supports an unknown depth of children, for example where you have nested groups within groups.

Given the field key “field_{some_hash}” of the field, this function will retrieve the field, and its parent most field, and so on until we reach the top of the field tree.


function custom_acf_get_field_name_by_key( $key ) {

    $field = acf_maybe_get_field( $key );

    if ( empty( $field ) || ! isset( $field['parent'], $field['name'] ) ) {
        return $field;
    }

    $ancestors = array();

    while ( ! empty( $field['parent'] ) && ! in_array( $field['name'], $ancestors ) ) {

        $parent = acf_get_field( $field['parent'] );

        $ancestors[] = $field['name'];

        $field = $parent;

    }

    $formatted_key = array_reverse( $ancestors );
    $formatted_key = implode( '_', $formatted_key );

    return "_$formatted_key";

}


Assume a case where I have a nested group:

 - dev_group_test | field_61ecf308ded3e | group
   ∟ title        | field_61ecf316ded3f | text
   ∟ location     | field_61ecf31cded40 | text
   ∟ sub_group    | field_61ecfa1fe5894 | group
     ∣
     ∟ sub_group_title | field_61ecfa2de5895 | text

If I want the full key of sub_group_title:

$meta_key = custom_acf_get_field_name_by_key( 'field_61ecfa2de5895' );
// result = _dev_group_test_sub_group_sub_group_title

If I want the full key of location:

$meta_key = custom_acf_get_field_name_by_key( 'field_61ecf31cded40' );
// result = _dev_group_test_location

NOTE: there may be more efficient ways to do this

Related Posts:

  1. Can I count the number of users matching a value in a multiple value key?
  2. Copying Custom Meta Values from existing post to a duplicate post
  3. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  4. WP_User_Query pulling ACF to loop
  5. Get all the posts where meta field with multiple choice has several values checked
  6. ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
  7. WordPress creates new lines in postmeta table on post update
  8. How to get custom image field of specific post id
  9. Getting user’s data, by custom field lookup (meta)
  10. Query Posts based on custom field value
  11. wordpress simple post multi rating with post_meta and user_meta
  12. save all acf options in one meta_value [closed]
  13. Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
  14. Can I exclude a post by meta key using pre_get_posts function?
  15. Where are custom field values stored in the database
  16. Custom post meta field effect on the performance on the post
  17. How to get custom post meta using REST API
  18. Difference between meta keys with _ and without _ [duplicate]
  19. Orderby meta_value only returns posts that have existing meta_key
  20. What is the index [0] for on post meta fields?
  21. What is “meta_input” parameter in wp_insert_post() used for?
  22. How to enable revisions for post meta data?
  23. The “_encloseme” Meta-Key Conundrum
  24. Best way to programmatically remove a category/term from a post
  25. Using get_post_meta with new_to_publish
  26. Advanced Custom Fields – Get custom fields from parent page
  27. Add custom field to the archive page?
  28. Matching Serialized Arrays with meta_query
  29. Custom field metabox not showing in back-end
  30. So much data in postmeta
  31. How to position a custom field before the editor
  32. Save custom user meta on registration
  33. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  34. How to hide meta box values from custom fields list?
  35. How to get users by a custom field / by user meta data?
  36. Auto sort the wp-admin post list by a meta key
  37. get_post_meta() unserialize issue – returns boolean(false)
  38. Display post_object content using Advanced Custom Fields plugin
  39. What is the advantage of the wp_options design pattern?
  40. Remove old custom field after import
  41. Storing meta fields multiple times OR once with multi dimensional array?
  42. How do you add a custom option to user data?
  43. Unable to get Preview of Uploaded image within a Custom Meta box
  44. Allow user to create instances of custom field
  45. display specific custom fields
  46. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  47. Meta keywords and descriptions plugin for manually editing meta for each page/post
  48. Retrieve custom fields on Categories, using WP-API
  49. passing argument to get_template_part() or a better way to code
  50. Is it possible to store arrays in a custom field?
  51. Get updated meta data after save_post hook
  52. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  53. Save HTML formatted data to post meta using add_post_meta()
  54. importing data from non-wordpress mysql db
  55. Order by custom field date?
  56. Show User Their Password
  57. Create meta boxes that don’t show in custom fields
  58. Transients vs CRON +Custom Fields: Caching Data Per Post
  59. How to update serialized data in the user meta data
  60. Unable to save datetime custom meta field using update_post_meta() function
  61. Up/Down voting system for WordPress
  62. Change content before writing to database
  63. post meta data clearing on autosave
  64. Create custom field on post draft or publish?
  65. Display info from custom fields in all images’ HTML
  66. Order Custom post type loop by custom field (datepicker)
  67. Ordering posts by anniversary using only day and month
  68. get_post_meta fields don’t show up on posts page
  69. Using Custom Function With Advanced Custom Fields
  70. Update meta values with AJAX
  71. How to break meta values into different items and avoid duplicates?
  72. automatically set “Featured Image” the same as the og:i that is set in a custom field
  73. copy attachments to another post type and change attachment url
  74. Cannot edit post meta fields with rest API
  75. ajax delete value from custom field array
  76. Problem with adding exta field in metabox in custom post type
  77. Save attachment custom fields on front end
  78. How can I sort get_users() by any value (last_name, user defined fields and more)
  79. How to use pagination with get_post_meta
  80. Add a post meta key and value only if it does not exist on the post
  81. Move value of one custom field to another
  82. Order posts according to user defined order for meta values?
  83. Calculate the sum of certain the_sub_fields
  84. Displaying posts with only upcoming dates according their custom field date value
  85. Displaying Custom Fields on Post with Genesis Child Theme
  86. Custom fields to save multiple values
  87. Custom fields: In what order are they saved into the DB?
  88. Function to change meta value in database for each post
  89. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  90. Get a post_id where meta_value equals something in a serialized meta_value field
  91. Get aggregate list of all custom fields for entire blog
  92. Displaying additional User Contact Information
  93. get_user_meta Short Profile Section
  94. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  95. Login & Register & Custom details WITHOUT plugin
  96. Custom field value based on other custom field values
  97. Send Multiple Custom Field Values Through the URL
  98. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  99. ACF won’t load from a custom JSON location
  100. How to save a ToggleControl value in a meta field?
Categories custom-field Tags advanced-custom-fields, custom-field, post-meta, user-meta
Why is variable not working on custom sql query using wpdb?
Register JS for block on frontend only

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress