Query pages by child term

What do you mean by “dynamic” ? Do you want it to work with different posts?

If so, that’s simple. Before your get_posts query function, get page terms, and pass them to your array. You can get taxonomies with

 <?php get_the_terms( $yourpostid, 'your_custom_taxonomy'); ?>