Wordpress 来自祖先页面的高级自定义字段数据
我试图使ACF数据在父页面下的两个级别的子页面上可用。我有一个解决方案,可用于子页面:Wordpress 来自祖先页面的高级自定义字段数据,wordpress,advanced-custom-fields,Wordpress,Advanced Custom Fields,我试图使ACF数据在父页面下的两个级别的子页面上可用。我有一个解决方案,可用于子页面: if ( $post->post_parent ) { $headingFont = get_field('community_heading_font', $post->post_parent); $bodyFont = get_field('community_body_font', $post->post_parent); $pr
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\u heading\u font”
我尝试过post->post\u parent->post\u parent
,也尝试过对变量使用post->post\u parent
:
$parentPage = $post->post_parent;
$grandparentPage = $parentPage->post_parent
要获取用于ACF函数的$祖父母页面ID,请使用wp\u get\u post\u parent\u ID()函数
$grandparentPage = wp_get_post_parent_id($post->post_parent);
$headingFont = get_field('community_heading_font', $grandparentPage);