/*
Theme Name: Hello Elementor Child
Theme URI: https://elementor.com/hello-theme/?utm_source=wp-themes&utm_campaign=theme-uri&utm_medium=wp-dash
Template: hello-elementor
Author: Elementor Team
Author URI: https://elementor.com/?utm_source=wp-themes&utm_campaign=author-uri&utm_medium=wp-dash
Description: Hello Elementor is a lightweight and minimalist WordPress theme that was built specifically to work seamlessly with the Elementor site builder plugin. The theme is free, open-source, and designed for users who want a flexible, easy-to-use, and customizable website. The theme, which is optimized for performance, provides a solid foundation for users to build their own unique designs using the Elementor drag-and-drop site builder. Its simplicity and flexibility make it a great choice for both beginners and experienced Web Creators.
Tags: accessibility-ready,flexible-header,custom-colors,custom-menu,custom-logo,featured-images,rtl-language-support,threaded-comments,translation-ready
Version: 3.1.1.1728897231
Updated: 2024-10-14 09:13:51

*/

add_action( 'elementor/query/child_posts_query', function( $query ) {
    // Ensure we're on a single post page
    if ( is_singular() ) {
        // Get the ID of the current post (parent post)
        $parent_post_id = get_the_ID();

        // Set the query to fetch posts with the current post as their parent
        $query->set( 'post_parent', $parent_post_id );

        // Specify the custom post type if needed
        $query->set( 'post_type', 'services' ); // Replace 'your_custom_post_type' with your actual post type

        // Optional settings for order and number of posts
        $query->set( 'orderby', 'date' ); // Orders by date
        $query->set( 'order', 'DESC' ); // Orders in descending order
        $query->set( 'posts_per_page', -1 ); // -1 to retrieve all child posts
    }
});
