Skip to content

Instantly share code, notes, and snippets.

@robwent
Created September 2, 2023 14:48
Show Gist options
  • Save robwent/04df5befa1ed1353e40553f345ea1a04 to your computer and use it in GitHub Desktop.
Save robwent/04df5befa1ed1353e40553f345ea1a04 to your computer and use it in GitHub Desktop.
Get child pages in ACF block
<?php
$args = array(
'post_type' => 'any',
'post_status' => 'publish',
'posts_per_page' => - 1,
'post_parent' => $post_id, // Available in ACF blocks by default
'order' => 'ASC',
'orderby' => 'menu_order',
'suppress_filters' => false,
);
$posts = get_posts( $args );
if ( ! $posts ) {
return false;
}
global $post;
?>
<div class="some-block">
<div class="row justify-content-center">
<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
<?php get_template_part( 'some-template' ); ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment