2016-02-29 93 views
0

我在獲取acf內容以在Wordpress循環中顯示時遇到了一些問題。 我使用page.php文件模板中的代碼如下:高級自定義字段內容不顯示在wordpress循環中

<?php $args = array (
'post_type' => 'test-box' 
); 
$the_query = new wp_query ($args); 
?> 
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query- >the_post(); ?> 

<?php 
the_field('acf_test_box_header'); 
the_field('acf_test_box_content'); 
?> 

<?php endwhile; else : ?> 

<p>There are no posts to display.</p> 

<?php endif; ?> 

的問題是兩個領域:當循環中,而不是返回「頭acf_test_box_header和acf_test_box_content不顯示其內容2「和」內容2「。如果我將它們移到循環之外,那麼它們將顯示輸入正確的內容。

任何想法?

+0

也許嘗試這個the_field( 'acf_test_box_header',get_the_ID())? –

+0

你的if語句不正確。 'if($ the_query-> have_posts()):' – CiprianD

+0

沒有 - 不會傷心。 – Stef

回答

1

試試這個:

$current_id = get_the_ID(); 
the_field('acf_test_box_content', $current_id); 
相關問題