1

I have a large amount of content that we are attempting to collect before we migrate to our new site structures. Normally the staff are supposed to relate content back to main entries to make sure that content ownership is maintained as seen below.

Screenshot of relationships on a child entry

However, they often would just add a page and then add a link to a relationship from a parent page as they discovered this was "easier":

Screenshot of entries that are being selected for display on a parent page

What I’m wondering is if there is a way for me to query entries that have not been related in the second method. The first example is simple, for example, I can query my topics that are missing relationship fields filled out like so:

{% set total = 
  craft.entries.section("topics")
    .departments(":empty:")
    .boardsCommissions(":empty:")
    .officials(":empty:")
    .processes(":empty:")
    .projects(":empty:")
    .topics(":empty:")
 %}
<h1>Topics missing all relationship fields: {{ total | length }}</h1>
{% for entry in total.all() %}
  {{ entry.title }} - {{ entry.author }} - {{ entry.id }}<br>
{% endfor %}

Where I’m getting confused is how I would query the second example, as what I want to do is query if the entries have been related to any other content on the site, which also includes matrix fields that may also have those relationships, instead of predefined fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.