WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[resolved] Field from parent page into child page (2 posts)

  1. NoArtworkAvailable
    Member
    Posted 2 years ago #

    I've been trying to get the value from a parent page's custom field (specifically an image url) into a child page so that it shows both on the parent and on the child page. Essentially an image that gets shown on the parent page and is pulled down and shown on the child pages too.

    The problem is that when I call the field on the child page, nothing comes up. I've tried to use parent page IDs, trying to tell it to get it from $post->post_parent as per this suggestion but to no avail.

    How can I pull the value to a child page from a parent page using Advanced Custom Fields? Any Suggestions?

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. elliotcondon
    Member
    Plugin Author

    Posted 2 years ago #

    Hi there,

    ACF's API functions the_field and get_field allow for a second parameter to specify the post_id to target. Therefore you could write soemthing like this:

    <?php
    
    global $post;
    $parent_id = $post->post_parent;
    
    $field_from_parent = get_field('field_name', $parent_id);
    
    ?>

    Good luck

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic