Skip to content

Instantly share code, notes, and snippets.

@davemac
Created April 10, 2014 09:39
Show Gist options
  • Save davemac/10362098 to your computer and use it in GitHub Desktop.
Save davemac/10362098 to your computer and use it in GitHub Desktop.
WordPress Get field from page parent
<?php
$parents = get_post_ancestors( $post->ID );
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
$title = ($parents) ? $parents[count($parents)-1]: $post->title;
?>
<?php if( get_field( 'dmc_hero_image', $id ) ) : ?>
<div class="row">
<div class="twelve columns page-title">
<img src="<?php the_field('dmc_hero_image', $id); ?>" width="990" class="hide-for-small" />
<h1><?php echo get_the_title($title); ?></h1>
</div>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment