add_action('elementor/query/readNextQueryx', function ($query) { // Retrieve the custom field 'what_to_read_next_articles' $postsID = get_post_meta(get_the_ID(), 'what_to_read_next_articles', true); // Ensure $postsID is an array and contains only valid, existing post IDs if (!is_array($postsID)) { $postsID = explode(',', $postsID); } $postsID = array_filter($postsID, 'get_post'); // Limit to 3 posts $postsID = array_slice($postsID, 0, 3); if (!empty($postsID)) { // Set the query parameters $query->set('post__in', $postsID); $query->set('posts_per_page', count($postsID)); $query->set('orderby', 'post__in'); $query->set('ignore_sticky_posts', true); $query->set('post_type', 'any'); // This will allow fetching any post type // Ensure we're only getting published posts $query->set('post_status', 'publish'); // Remove any category or tag constraints $query->set('category__in', []); $query->set('tag__in', []); } else { // If no valid post IDs, return no results $query->set('post__in', [0]); } // Remove the function if it exists to prevent double execution remove_action('elementor/query/readNextQueryx', __FUNCTION__); }, 10, 1);