Support

Account

Home Forums General Issues gettimg custom field values from parent and grandparent page? Reply To: gettimg custom field values from parent and grandparent page?

  • You could use the current page’s ‘post_parent’ field as the argument for get_ancestors() to ascend the page hierarchy:

     global $post;
    $parent = $post->post_parent;
    $grandparents = get_ancestors( $parent, 'page');
    $country = get_field( 'country', $grandparents[0] );
    

    Haven’t tested this but should work