Home › Forums › General Issues › Matching $_POST key and ACF field name › Reply To: Matching $_POST key and ACF field name
You have the field names and are looking for the field keys. It would be possible to do this if those fields already exist in the database for the post using get_field_object($field_name, $post_id)
However, since you are creating post then these fields do not exist and there isn’t any way to match them up.
You have to know the field keys.
You could build an array of field name => field key pairs
$fields = array(
'field_name_1' => 'field_key_1',
'field_name_2' => 'field_key_2',
// etc...
);
foreach ($_POST as $field_name => $value) {
update_field($fields[$field_name], $value, $post_id);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.