Hello,
I am having an insanely difficult time finding out how to programmatically save to a selection choice with ACF. Here’s what I have.
$new_cat_id = wp_insert_category($new_cat);
$values = array('choices'=>'product');
update_field('cat-type', $values, 'product_cat_'.$new_cat_id);
This code actually shows the correct ‘product’ selection being made when I go to the admin page for this, but I am unable to grab it using:
$product = get_field('cat-type','product_cat_'.$category->term_id);
If I..
print_r($product);
…the wrong selection shows up in the array but if I look at it from the site administration, it shows with the correct option selected. I have gone through every tutorial I can find but none of them have been successful. Any help would be greatly appreciated. Thank you!
See this page: http://www.advancedcustomfields.com/resources/update_field/
You need to use the field key, something that looks like: “field_4fc5ab37e1819lol”
The page goes on to talk about data entries and reference entries. To get values from ACF using the ACF functions both the value & reference must be interested.
OK, this helped to solve this issue. What I ended up with is:
$new_cat_id = wp_insert_category($new_cat);
$values['choices'] = 'product';
update_field('field_54d4c68c4aa5e',$values, 'product_cat_'.$new_cat_id);
Thanks for pointing me in the right direction.