2017-04-04 72 views
0

我正在编写一个代码,我可以在每次在自定义帖子类型上编辑帖子时收到通知。ACF的中继器字段不是呈现子字段

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

我想知道我可能会做错什么。电子邮件附带了帖子中的确切行数,只有字段没有被显示。

其他一切似乎都工作正常。

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

'$ post'是'$ post-> ID'吗? –

+0

嗨@TyBailey,我试过'$ post-> ID',但没有区别。 – danrodrigues

+0

什么是您作为参数传递的$ post变量?它是帖子对象还是......?此外,您正在执行此功能的动作/过滤器? –

回答

1

首先,确保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()则没有。

+0

谢谢!删除'$ post'不起作用,但是使用'get_sub_field()'取而代之。 :) – danrodrigues

+0

'the_field()'和'get_field()'发生同样的情况' –