1

不使用 page_id 参数时,我似乎无法让 ACF 工作。这是我的代码在工作时的样子:

'outreach' 是 field_name,10 是 page_id

<p><?php the_field('outreach', 10); ?></p>

当我不包含 page_id 时,它根本不起作用:

<p><?php the_field('outreach'); ?></p>

ACF 网站上的文档说您不需要 page_id 参数,但我正在使用多站点安装,所以我想知道这是否会以某种方式搞砸。

4

2 回答 2

1

如果您不包含页面 ID,那么您需要确保您是the_fieldThe Loop内部调用的。

<?php 
// a page id is required here
the_field('outreach', 10);

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();

        // page id isn't required in here
        the_field('outreach');

    } // end while
} // end if
?>
于 2014-01-03T22:47:54.353 回答
0

我会尝试写出该特定页面的页面 ID 并查看它返回的内容。

//Page ID
<?php echo get_the_ID(); ?> 

然后你可以使用:

<?php the_field('outreach', get_the_ID()); ?> 
于 2014-01-03T22:54:21.807 回答