Null Length Error on Craft Version 3 I am not super fluent in Twig and I inherited a website from a company that built the site in Craft v2. The site was upgraded to version 3 of Craft recently and one of the template pages is throwing an error where on version 2 of Craft it was not. Code:
{% set faqs = craft.entries.section('FAQ').search('slug::' ~ entry.slug).first() %}

{% if faqs.questionsanswers|length &gt; 0 %}
  &lt;a href=&quot;#link&quot;&gt;FAQs&lt;/a&gt;
{% endif %}

This is throwing an error: Impossible to access an attribute (&quot;questionsanswers&quot;) on a null variable.
So since it was returning null I changed the code to this which seems to be working:
{% if faqs is not null and faqs is not empty %}
  &lt;a href=&quot;#link&quot;&gt;FAQs&lt;/a&gt;
{% endif %}

My question is why would this code not work for version 3 when it was working correctly for version 2? Why would the length return null instead of 0? I did not do the upgrade but maybe something was missed? (This is a template page and some of the entries do have FAQs and some don't) Or perhaps something with the structure of the version 3 of Craft has changed? Lastly if there is a better way to do/code what is being done I would love to hear it.
The error tells you that faqs is null. As you're using the first() function to execute your element query, this means that your query has no matches.

Are you sure that the section handle (FAQ) is in uppercase?
The correct way to create an entry query in Craft 3 is craft.entries(). Although it may work without the parenthesis, it can't hurt to add them.
You can replace .search('slug::' ~ entry.slug)  with .slug(entry.slug). It's easier to understand and should have the same effect.
Are you sure that the query always returned something in Craft 2? It may be worth adding a null check to avoid the error: {% if faqs and faqs.questionsanswers and faqs.questionsanswers|length &gt; 0 %}