2016-01-28 112 views
0

我想在子頁面上顯示ACF中繼器字段的結果。當前的代碼示例:在子頁面上顯示ACF中繼器字段

<?php if(have_rows('recommended-properties')): ?> 
    <?php while (have_rows('recommended-properties')) : the_row(); ?> 
    <?php the_sub_field('recommended-properties-title'); ?> 
    <?php the_sub_field('recommended-properties-description'); ?> 
    <?php endwhile; ?> 
<?php endif; ?> 

現在,我想我或許可以存儲父頁面ID的變量,並使用同樣的方法,你可以從另一個帖子得到的值(見:http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/

我試過如下:

<?php $parentPageId = wp_get_post_parent_id($post_ID); ?> 
<?php if(have_rows('recommended-properties', echo $parentPageId;)): ?> 
    <?php while (have_rows('recommended-properties', echo $parentPageId;)) : the_row(); ?> 
    <?php the_sub_field('recommended-properties-title'); ?> 
    <?php the_sub_field('recommended-properties-description'); ?> 
    <?php endwhile; ?> 
<?php endif; ?> 

但遺憾的是沒有運氣。對於我可以從哪裏出發的任何建議?

非常感謝!

回答

3

你不需要添加回聲,當你在函數中添加參數

試試下面的代碼

<?php $parentPageId = wp_get_post_parent_id($post_ID); ?> 
<?php if(have_rows('recommended-properties', $parentPageId)): ?> 
    <?php while (have_rows('recommended-properties', $parentPageId)) : the_row(); ?> 
    <?php the_sub_field('recommended-properties-title'); ?> 
    <?php the_sub_field('recommended-properties-description'); ?> 
    <?php endwhile; ?> 
<?php endif; ?> 
+1

你應該刪除「;」在$ parentPageId後使用它時,在函數調用 –

+0

謝謝Luka,我解決了這個問題。 – Krish

相關問題