Home › Forums › Add-ons › Repeater Field › Initialize repeater field or programmatically find field_key › Reply To: Initialize repeater field or programmatically find field_key
Hi @elliot – thanks very much for your response.
I have altered the function so that I can pass it the field key – is there really know way to find this?
I have one final problem, if you don’t mind? My code is below, it is not correctly inserting the data when no rows exist already (the second update_field call).
Thanks,
Adam
function acf_add_repeater_row($field_name, $post_id, $values, $field_key = '') {
$field_obj = get_field_object($field_name, $post_id );
// var_dump($field_obj['value']);
if( $field_key == ''){
$field_key = $field_obj['key'];
}
// check whether the meta fields exist in the DB
if( $field_obj['value'] ) {
// they do, let's add a row
array_push( $field_obj['value'], $values );
update_field( $field_key, $field_obj['value'], $post_id );
}
else if ($field_key) {
// they don't, let's create them
update_field( $field_key, $values, $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.