0
我想在父頁下的兩個級別上的子頁面上提供ACF數據。我有一個解決方案,使其可用於兒童頁面:來自祖先頁面的高級自定義字段數據
if ($post->post_parent) {
$headingFont = get_field('community_heading_font', $post->post_parent);
$bodyFont = get_field('community_body_font', $post->post_parent);
$primaryColor = get_field('community_primary', $post->post_parent);
$secondaryColor = get_field('community_secondary', $post->post_parent);
$fifteenSecondaryColor = get_field('community_fifteen_secondary', $post->post_parent);
$tertiaryColor = get_field('community_tertiary', $post->post_parent);
}
但是,一旦我們是更深的級別,此信息不可用。也就是說,ACF字段'community_heading_font'
不可用於最初爲該字段提供數據的頁面的孫子。
我試過post->post_parent->post_parent
,我也試着對一個變量使用post->post_parent
:
$parentPage = $post->post_parent;
$grandparentPage = $parentPage->post_parent