【发布时间】:2017-07-20 06:19:35
【问题描述】:
我正在尝试使 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
【问题讨论】:
标签: wordpress advanced-custom-fields