WordPress Query to show children of the current post using Elementor to design the page

I am trying to create a custom query to show the children of the current post. I am use the custom post type “services” and using Elementor as the theme builder.

Elementor requires the query to be formatted as like this

// Showing multiple post types in Posts Widget
add_action( ‘elementor_pro/posts/query/my_custom_filter’, function( $query ) {

// Here we set the query to fetch posts with
// post type of ‘custom-post-type1’ and ‘custom-post-type2’
$query->set( ‘post_type’, [ ‘custom-post-type1’, ‘custom-post-type2’ ] );

} );

and I have found this example on stack exchange that should do what we want

<?php

$args = array(
‘post_type’ => ‘page’,
‘posts_per_page’ => -1,
‘post_parent’ => $post->ID,
‘order’ => ‘ASC’,
‘orderby’ => ‘menu_order’
);

$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

<?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

<div id=”parent-<?php the_ID(); ?>” class=”parent-page”>

<h1><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></h1>

<p><?php the_advanced_excerpt(); ?></p>

</div>

<?php endwhile; ?>

However I am having problems putting them together.

I would appreciate any help.

Thank you

Read more here:: WordPress Query to show children of the current post using Elementor to design the page

Leave a Reply

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