Rob
Rob

Reputation: 6370

Wordpress - Show custom fields of children on parent page

I'm using the Advanced custom field plugin and having trouble showing custom fields of children in a loop. I tried this:

<?php <br /> $pages = get_pages(array('child_of' => $post->ID));

foreach($pages as $page) 
{
setup_postdata($page);
$fields = get_fields(); print_r($fields);
}

wp_reset_query();
?>

When I put print_r($page) in it says 1111 so that bit is working (as there's 4 children items).

That code just prints the custom field names of the parent rather than the children, how can I show the children's custom fields?

Upvotes: 1

Views: 599

Answers (2)

Rob
Rob

Reputation: 6370

It should've been post instead of page, doh!

http://support.plugins.elliotcondon.com/discussion/43/show-page-children-or-subpages-with-custom-fields

Upvotes: 1

Christophe
Christophe

Reputation: 4828

Have you tried this?

get_pages(array('child_of' => $post->ID, 'parent' => $post->ID, 'hierarchical' => 0))

Upvotes: 0

Related Questions