Hi
Check out this answer I gave on the support section of acf.
http://support.advancedcustomfields.com/discussion/comment/9283#Comment_9283
You should be able to get what you want using get_field_object.
That’s great – thanks. Your example uses this to get the custom field opject:
$field_obj = get_field_object( 'field_506d7b9428874', $post_id );
The “field_506d7b9428874”, where would that come from? I’m assuming it is the custom field ID, but I cannot see that in the ACF admin screens since it is all AJAX and these codes don’t appear in any URLs. Do I need to look at the page HTML source to get that? Or can I just use the “field name” slug as it appears in the admin screen?
— Jason
You can view this field key in the admin area by going into Custom Fields > your field group > Screen Options (top right) > and set “Show Field Key” to Yes
See the pic for clarification
http://tinypic.com/r/rk7bsh/6
This will show you the field key next to your custom fields.
BTW,
You can also see these keys in your MySQL db if you search for the field name in the postmeta table.
Brilliant! You’re a star 🙂 I seldom think of looking in that “screen options” drop-down panel, and forget it contains contextual display options.
I will be using this to expand the grade codes of second-hand disks in this shop:
http://www.soulbrother.com/shop/turn-you-to-love/
Just a simple code is stored (M and M in that example), but I would like to display the full description of those codes, which is defined in the ACF field.
I’ll post the code I use, then close this ticket.
Here we go – works a dream. In the WooCommerce meta.php template, I check if the get_field_object() function exists (because it won’t if ACF is not enabled), then fetch the two lists:
if (function_exists('get_field_object')) {
$field_obj = get_field_object( 'field_5062e50c7da52', $product->id );
if (!empty($field_obj['choices'])) $disc_grade_choices = $field_obj['choices'];
$field_obj = get_field_object( 'field_5062e62519095', $product->id );
if (!empty($field_obj['choices'])) $sleeve_grade_choices = $field_obj['choices'];
}
Further down, after I fetch the custom fields into $disc_grade and $sleeve_grade, I check if those grades are an index value in the lists, then switch in the description if they are:
if (!empty($disc_grade_choices) && !empty($disc_grade_choices[$disc_grade])) $disc_grade = $disc_grade_choices[$disc_grade];
Always erring in the side of safety, of course, because you cannot guarantee a given plugin or theme is going to be there.
The code isn’t rocket science, I know, but may be useful to someone. Thanks again.
— Jason