Query a list of child pages for a parent by Page name

Description

This code is to be used in page template to query a list of children of the current page.

PHP Source Code

                        
                          								<?php
								$services_page = get_page_by_path('services'); // Get the "Services" page by its slug

								if ($services_page) {
									$args = array(
										'post_type'      => 'page',
										'posts_per_page' => -1,
										'post_parent'    => $services_page->ID, // Use the ID of "Services" as the parent
										'order'          => 'ASC',
										'orderby'        => 'menu_order'
									);

									$services_children = new WP_Query($args);

									if ($services_children->have_posts()) :
										while ($services_children->have_posts()) : $services_children->the_post();
											?>
											
                                <div class="solutions-single">
                                    <h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
                                    <a href="<?php the_permalink(); ?>"><i class="fas fa-plus"></i></a>
                                </div>
											
											
											<?php
										endwhile;
										wp_reset_postdata();
									else :
										echo '<p>No child pages found under Services.</p>';
									endif;
								}
								?>
                        
                        


Post Categories