I don't think the issue is within the code that we shared, we can use it to restrict the posts on a Toolset view. Check the test server on this page hidden link
It only returns the linked cocktails, even if the view is configured to return all cocktails, because we use the following custom code in Toolset->Settings->Custom code, which is similar to adding it to functions.php.
I do not understand this part:
we use the following custom code in Toolset->Settings->Custom code
I have never used this. How to use this?
Does it create a shortcode?
I went to the demo website, I copied the custom code to my demo site,
but then I don't know what to do with it,
since I don't use Blocks.
Where does it fit in the php function?
we use the following custom code in Toolset->Settings->Custom code
I have never used this. How to use this?
Does it create a shortcode?
This is our alternative to editing directly the functions.php file and adding custom code. The custom code can be for a shortcode or for a hook just like yours.
The last code that I provided in my reply #1787625 does return the list of Cocktails posts that are linked to any Oeuvre post. And my reply #1787911 demonstrates how to use it inside a hook. So, I don't see why we'll need to convert the IDs to string and pass it to "toolset_get_related_posts" if it is already working with numeric IDs.
I, previously, understood that $query->set( 'post__in', $ids) is how Elementor allow to hook into its lists or queries. But that's something you should check with the Elementor team.
So, regarding your last code, I'll see that you need to debug it in order to understand what's going on. I'll suggest using ways to check the progress of the code using error_log function, or using a debugging solution such as Xdebug.
// the following line will write the content of the $posts object to the debug.log file, in a readable way.
error_log( print_r( $posts, true ) );