Home › Forums › Backend Issues (wp-admin) › Convert repeater to single field › Reply To: Convert repeater to single field
Thanks John, you are always so usefull !!
Just for now I started with a simplified version :
function update_fields_value( $post_id ) {
if (get_post_type($post_id) != 'annuaire') {
return;
}
$localisations = get_field('ACF_localisation', $post_id );
if ( $localisations ) {
$first_localisation = $localisations[0];
update_field( 'field_5f0846f3dbd27', $first_localisation['ACF_adresse_ligne_1'], $post_id );
update_field( 'field_5f08542b4627f', $first_localisation['ACF_adresse_ligne_2'], $post_id );
update_field( 'field_5f08544746280', $first_localisation['ACF_code_postale'], $post_id );
update_field( 'field_5f08548f46281', $first_localisation['ACF_localite'], $post_id );
}
$contacts = get_field('ACF_presentation_du_personnel', $post_id );
if ( $contacts ) {
$first_contact = $contacts[0];
if ( $first_contact['ACF_poste_du_contact'] != "" ) {
$contact_details = $first_contact['ACF_prenom_du_contact'] . ' ' . $first_contact['ACF_nom_du_contact'] . ' (' . $first_contact['ACF_poste_du_contact'] . ')';
} else {
$contact_details = $first_contact['ACF_prenom_du_contact'] . ' ' . $first_contact['ACF_nom_du_contact'];
}
update_field( 'field_5f0844ed062f3', $contact_details, $post_id );
}
}
add_action('acf/save_post', 'update_fields_value', 15);
I have just seen 5/6 posts for the above code testing and realise that there are encoding errors. With this solution I will force the customer to at least open, save (to update the fields) and check the new contents.
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.