Home › Forums › General Issues › Count relationships › Reply To: Count relationships
2 issues
1) you need to supply the post ID for both getting and setting a field.
2) count may be giving an error if no value is being returned
function acf_save_post_nombre_avis ($post_id) {
$nombre_avis = 0;
$avis_clients= get_field('avis_clients', $post_id);
if (!empty($avis_clients)) {
$nombre_avis = count($avis);
}
update_field('nombre_avis', $nombre_avis, $post_id);
}
add_action('acf/save_post', 'acf_save_post_nombre_avis', 20);
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.