Created
January 27, 2014 09:53
-
-
Save simonwheatley/8645866 to your computer and use it in GitHub Desktop.
Getting an Advanced Custom Fields field_key from a field_name and field_group.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get a field key from a field name. Why isn't this an | |
* ACF API function? | |
* | |
* @param string $field_group The name of the field_group to search | |
* @param string $field_name The name of the field to find a key for | |
* @return string|bool The field key if found, else false | |
* | |
* @author Simon Wheatley | |
**/ | |
protected function get_field_key( $field_group, $field_name ) { | |
$field_definitions = apply_filters('acf/field_group/get_fields', array(), $field_group ); | |
foreach ( $field_definitions as $def ) | |
if ( $field_name == $def[ 'name' ] ) | |
return $def[ 'key' ]; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Simon --
Super handy ... if I could only make it work ;-)
What value does this function take for $field_group? Individual fields have "Field Label" and "Field Name", which I set in ACF's UI. But there's nothing similar for the Field Group.
In ACF, I have a group "My Group". Should I pass "My Group"? "my-group"? Some id value that I need to find in the DB?