Support

Account

Home Forums General Issues Inherit field content from parent page? Reply To: Inherit field content from parent page?

  • <?php 
    if ( !function_exists( 'get_inherited_field' ) ) {
    
        function get_inherited_field( $field ) {
            $value = get_field( $field );
            if ( !$value ) 
                $value = get_field( $field, wp_get_post_parent_id( get_the_ID() ) );
            return $value;
        }
    
        function the_inherited_field( $field ) {
            echo get_inherited_field( $field );
        }
    
        function has_inherited_sub_field( $field ) {
            return ( has_sub_field( $field ) or has_sub_field( $field, wp_get_post_parent_id( get_the_ID() ) ) );
        }
    
        function the_inherited_sub_field( $field ) {
            $value = get_sub_field( $field );
            if ( !$value ) 
                $value = get_sub_field( $field, wp_get_post_parent_id( get_the_ID() ) );
            echo $value;
        }
    }
    ?>
    
    <?php the_inherited_field('field-name'); ?>
    
    <?php while(has_inherited_sub_field('repeater-field-name')): ?>
        <?php the_inherited_sub_field('repeater-field-name'); ?>
    <?php endwhile; ?>