WordPress.org

Support

Support » Themes and Templates » [Resolved] Get a custom field value from a parent page to show on a child page

[Resolved] Get a custom field value from a parent page to show on a child page

  • Hello,

    I’m using custom fields as descriptions for a site’s sections: pages with children pages. The top pages have all the same custom field key, each one with different values.

    Example:
    top page 1 (custom field key: color; custom field value: blue;)
    – child page 1
    – child page 2

    top page 2 (custom field key: color; custom field value: yellow;)
    – child page 3
    – child page 4

    What I would like to accomplish is this: on each child page I would like to display the value of the custom field from the parent page. “Child page 1” and “Child page 2” have somewhere on the page “blue” and
    “Child page 3” and “Child page4” have somewhere on the page “yellow”

    Is that possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi

    @esmi

    Forum Moderator

    I’ve not tried it but something like:

    <?php $color = get_post_meta($post->post_parent, 'color', true);
    echo $color;?>

    should work if it’s used within the Loop.

    Thank you esmi. That works like a charm.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Get a custom field value from a parent page to show on a child page’ is closed to new replies.