Checking if current entry exists in an entry custom field in a different entry I thought this would be simple but I am having no luck with it. I have a channel called "Posts" and for each Post there an "entry" custom field which lists all "Projects" (a structure). The user can select up to 3 of these within a Post. 

The idea is to relate a current news Post with an existing project. In my Project entry template I basically want to check to see if the current project has been selected in the "relatedProjects" entry field. If it has, I need it to show a "Related Posts" title and then below that list each Post. 

The thing I can't fathom out is how to have a section title that doesn't appear in the loop for each Post.
You can get the posts related to your "entry" (the currently shown project) with a
craft.entries element criteria model where you set the relatedTo parameter like so:

{% set relatedPosts = craft.entries.relatedTo({
    targetElement: entry
}) %}


Then check if this does find anything using Twig's length filter:

{% if relatedPosts|length %}
    &lt;aside&gt;
        {% for relatedPost in relatedPosts %}
            {{ relatedPost.title }}
        {% endfor %}
    &lt;/aside&gt;
{% endif %}