douqulv6059 2017-04-04 13:28 采纳率: 0%
浏览 37
已采纳

ACF中继器字段不渲染子字段

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 );
}
  • 写回答

1条回答 默认 最新

  • douque2016 2017-04-04 13:59
    关注

    First, make sure that participantes is the name of the repeater. Then, remove the $post variable in every the_sub_field().

    Change

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

    To

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

    You already mentioned which repeater's values to fetch(and you are in that repeater's while loop) so you don't need to insert that again on the sub field.

    Also, you might need to use get_sub_field() and not the_sub_field(). The difference is that the_sub_field() echoes the value and get_sub_field() doesn't.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题