Advanced Custom Fields – Get custom fields from parent page

I’m using Advanced Custom Fields making it easier for my client to manage his content.

On all of my child- and parent pages i would like to have the same header image and sidebar information.

Allthough i wish to make “Parent Page #1” and “Parent Page #2” have different information and this is controlled with Advanced Custom Fields by the Client.

Right now the cleint goes to every parent and child page to fill out the information manually – i would like it to only be filled out on the Parent page. Making the Child pages get the information from their parent page.

Parent Page #1

  • Child page #1 – Should get Custom Field values from “Parent Page 1”
  • Child page #2 – Should get Gets Custom Field values from “Parent Page 1”
  • Child page #3 – Should get Gets Custom Field values from “Parent Page 1”

Parent Page #2

  • Child page #1 – Should get Gets Custom Field values from “Parent Page 2”
  • Child page #2 – Should get Gets Custom Field values from “Parent Page 2”
  • Child page #3 – Should get Gets Custom Field values from “Parent Page 2”

So here’s my question.

On my “parent page template” I use the following to generate the image:

<img src="https://wordpress.stackexchange.com/questions/111351/<?php the_field("header_image'); ?>">

So how do I, on my “Child page template” get the field “header-image” from the parent page of the child page?

3 s
3

In your loop, you can access the id of the parent page with $post->post_parent.

You just need to pass this value as second parameter:

<img src="https://wordpress.stackexchange.com/questions/111351/<?php the_field("header_image', $post->post_parent ); ?>">

Leave a Comment