Support

Account

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; ?>