/* 
Theme Name: Hello Elementor Child
Theme URI: https://github.com/elementor/hello-theme-child/
Description: Hello Elementor Child is a child theme of Hello Elementor, created by Elementor team
Author: Elementor Team
Author URI: https://elementor.com/
Template: hello-elementor
Version: 2.0.0
Text Domain: hello-elementor-child
License: GNU General Public License v3 or later.
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Tags: flexible-header, custom-colors, custom-menu, custom-logo, editor-style, featured-images, rtl-language-support, threaded-comments, translation-ready
*/

/* Add your custom styles here */
add_action( 'elementor/query/related_projects_query', function( $query ) {
    if ( ! is_singular('community') ) {
        return;
    }

    $related = get_field('related_project'); // ACF relationship field on Community CPT

    if ( empty($related) || ! is_array($related) ) {
        $query->set('post__in', [0]); // Avoid showing all posts
        return;
    }

    $related_ids = array_map(function($post) {
        return is_object($post) ? $post->ID : (int) $post;
    }, $related);

    $query->set('post_type', 'project');
    $query->set('post__in', $related_ids);
    $query->set('orderby', 'post__in');
});
