Home › Forums › Front-end Issues › Child pages of parent with post object › Reply To: Child pages of parent with post object
Hi ForbiddenChunk! You should use the post ID instead of the post object in the post_parent argument. Take a look at this, may helps you in the future https://gist.github.com/luetkemj/2023628
<?php
$post_object = get_field('second_subpage');
if( $post_object ):
// get the post id from the post object
$post_ID = $post_object->ID;
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<!-- here -->
<?php
$args = array(
'post_parent' => $post_ID,
'post_type' => 'page',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) :
while ( $parent->have_posts() ) : $parent->the_post();
?>
<div class="page_link page_link--small count_five" style="background-image:url('<?php the_post_thumbnail_url(); ?>');">
<div class="page_link__title">
<h2><?php the_title(); ?></h2>
<?php the_field('preview'); ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<!-- end -->
<?php wp_reset_postdata(); ?>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.