Hi guys,
I am trying to use a Gravity Form to create a new post within a CPT. The CPT consists of several ACF fields some of them being select fields.
The fields are all being populated as expected but when I try to do get_field_object and get a list of the options there is nothing returned unless I go in as admin and save the form via the CPT and ACF Pro fields.
The reason I need a list of the options is to output the value on the frontend.
I have looked in the database and I can see there are associated rows with matching names with underscores pointing to the field id. e.g.:
$gender = get_field_object('gender');
$genderValue = get_field('gender');
<div><strong>Gender:</strong> <?php echo $gender['choices'][$genderValue]; ?></div>
Is there anyway I can either get_field_object without this field being populated or automatically populate the database with the underscore fields (excluding manually creating them when I submit the initial Gravity Form)?
Thanks for any help.
Hi @engineroom
Please keep in mind that ACF saves two entries in the database, the value which is like this:
field_name : the value
And the reference, which is like this:
_field_name : field_123456789abc
It seems Gravity Form only creates the value, which makes ACF can’t get the correct object for that value. To fix it, you can update the entries by using the update_field() function when Gravity Form is saving the custom fields. To learn how to do it, kindly get in touch with Gravity Form support.
I hope this makes sense 🙂