2017-04-04 71 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()'發生同樣的情況' –