1

我正在使用高级自定义字段,并试图将子页面中的内容拉到主页上

我似乎无法让下面的工作,有没有人有任何为什么它不工作?

页面设置如下:

-父页面(页面 id = 4)

--子页面

--子页面

<ul>
    <?php
    $children = get_children( array( 'post_parent' => get_the_ID(4) ) );
    if ( $children ) {
        foreach( $children as $child ) { ?>
            <li>
                <?php echo get_the_title($child->ID); ?>
                <?php the_field( 'content', $child->ID ); ?>
            </li>
    <?php } } ?>
</ul>
4

2 回答 2

2

“get_the_ID()”函数使用不正确,可以省略。您的代码变为:

$children = get_children( array( 'post_parent' => 4 ) );

您可能还想指定 post_type 参数。现在您的函数也将返回附件。

$children = get_children( array( 'post_parent' => 4, 'post_type' => 'page' ) );
于 2014-03-11T10:58:16.230 回答
0

您可能会在 ACF 文档中找到答案:

http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page/

于 2014-03-11T10:48:40.397 回答