I am writing a code where I can get notifications everytime a post is edited on a custom post type.

It is working fine, but ACF’s repeater field is not rendering its subfields on the email.

I wonder what I could be doing wrong. The email comes with the exact number of rows in the post, only the fields are not being displayed.

Everything else seems to be working fine.

function send_mails_on_update( $new_status, $old_status, $post )
{
    if ( $new_status != $old_status or 'form_caravanas' !== get_post_type( $post ) )
        return 'text/html';

    $subscribers = get_users( array ( 'role' => 'administrator' ) );
    $emails      = array ();

    foreach ( $subscribers as $subscriber )
    $emails[] = $subscriber->user_email;

    $nome = get_field('nome', $post);
    $sobrenome = get_field('sobrenome', $post);
    $ddd_celular = get_field('ddd_celular', $post);
    $email = get_field('email', $post);
    $nome_da_igreja = get_field('nome_da_igreja', $post);
    $tipo_de_transporte = get_field('tipo_de_transporte', $post);
    $cidade_e_estado_de_origem = get_field('cidade_e_estado_de_origem', $post);

    $repeater = get_field('participantes', $post);

    $participantes = '';

    if( have_rows('participantes', $post) ):
    while( have_rows('participantes', $post) ): the_row();
    $nome_participante = the_sub_field('nome', $post);
    $sobrenome_participante = the_sub_field('sobrenome', $post);
    $ddd_celular_participante = the_sub_field('telefone', $post);
    $email_participante = the_sub_field('email', $post);

    $participantes.= sprintf( '<ul>
        <li>Nome: ' . $nome_participante . '</li>
        <li>Sobrenome: ' . $sobrenome_participante . '</li>
        <li>Celular: ' . $ddd_celular_participante . '</li>
        <li>Email: ' . $email_participante . '</li>
    </ul>' ); endwhile; endif;

    $participantes.= '';

    $body = sprintf( '<html><head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"></head><body>
    <div class="container"><p><h3>Responsável</h3></p>
    <p><strong>Nome:</strong> ' . $nome . '<br>
    <strong>Sobrenome:</strong> ' . $sobrenome . '<br>
    <strong>DDD + Celular:</strong> ' . $ddd_celular . '<br>
    <strong>Email:</strong> ' . $email . '<br>
    <strong>Nome da Igreja:</strong> ' . $nome_da_igreja . '<br>
    <strong>Tipo de Transporte:</strong> ' . $tipo_de_transporte . '<br>
    <strong>Cidade e Estado de Origem:</strong> ' . $cidade_e_estado_de_origem . '<br>
    </p>
    <p><h3>Participantes</h3></p>
    <p>' . $participantes . '</p>
    </div></body></html>' );


    wp_mail( $emails, 'A caravana "' . get_the_title( $post ) . '" foi atualizada!', $body );
}

Read more here: ACF’s repeater field is not rendering subfields


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: