WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[resolved] calling custom fields of child on parent pages (3 posts)

  1. Michele
    Member
    Posted 7 months ago #

    I'm trying to call in my custom field data from child pages to the parent page.

    I am getting this error:
    Fatal error: Call to undefined method WP_Post::get_field() in /data/24/2/46/90/2861742/user/3145138/htdocs/ygs/wp-content/themes/ygs/page_parent.php on line 30

    <?php
    	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
    	$count = 0;
    	foreach($pages as $page)
    	{
    		$content = $page->post_content;
    		$description = $page->get_field('description');
    
    	?>
    		<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    
    		<div class="entry"><?php echo $description ?></div>
    
    	<?php
    	}
    ?>

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

  2. Ov3rfly
    Member
    Posted 7 months ago #

    Instead of this:
    $description = $page->get_field('description');

    Use something like this:
    $description = get_field('description', $page->ID);

    See also here:
    http://www.advancedcustomfields.com/resources/functions/get_field/

  3. Michele
    Member
    Posted 7 months ago #

    That appears to have fixed it! Thanks :)

Reply

You must log in to post.

About this Plugin

About this Topic