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);