Get Page with get_posts() and setup postdata

Really is a cool way to do things…

$args = array(
	'posts_per_page'   => -1,
	'orderby'          => 'date',
	'order'            => 'DESC',
	'post_type'        => 'page',
	'post_parent'      => 7, // page ID
);
$posts_array = get_posts( $args ); 

foreach( $posts_array as $post ) : setup_postdata( $post );
	
	$title = get_the_title();
	echo '<li>'.$title.'<li>';

endforeach;

 

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 2 =