2017-07-19 20 views
0

親の下の2レベルの子ページで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使用することを試みた:wp_get_post_parent_id()関数を使用して、あなたのACFの機能で使用するために$ grandparentPage IDを取得するには

$parentPage = $post->post_parent; 
    $grandparentPage = $parentPage->post_parent 

答えて

関連する問題