ACF 转发器字段未呈现子字段

ACF's repeater field is not rendering subfields

我正在编写代码,每次在自定义 post 类型上编辑 post 时我都可以收到通知。

工作正常,但 ACF 的转发器字段未在电子邮件中呈现其子字段。

我想知道我做错了什么。电子邮件附带 post 中的确切行数,只是未显示字段。

其他一切似乎都正常。

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

首先,确保participantes是转发器的名称。然后,删除每个 the_sub_field().

中的 $post 变量

改变

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

$nome_participante = the_sub_field('nome');
$sobrenome_participante = the_sub_field('sobrenome');
$ddd_celular_participante = the_sub_field('telefone');
$email_participante = the_sub_field('email');

您已经提到要获取哪个中继器的值(并且您在该中继器的 while 循环中)因此您不需要在子字段中再次插入它。

此外,您可能需要使用 get_sub_field() 而不是 the_sub_field()。区别在于 the_sub_field() 回显值而 get_sub_field() 不回显。