I have 2 content types. Question and Answer. Answers hava a entity reference field and contain reference to certain questions. Now, I want to build a view with listing of questions and number of answers to each question.

So, my view has one field title. Another field title with set up relationship (to show related answers). Filter is set up to show only published nodes and node types of Question and Answer. Query setings - distinct.

Result: I get all questions with all answers. Like this:
Q1 (published)
-someanswer1 (published)
-someanswer2 (unpublished)
Q2 (published)
-someanswer3 (unpublished)
-someanswer4 (unpublished)

Problem: Only Questions get filtered by using filter - published nodes. The referenced nodes - answers are not filtered and are shown all published as well as unpublished.

What would be the best approach to show ONLY published both answers and questions? Thank you

3 Answers 3


While there might be other approaches, I'd go with Views Field View.

It allows you to use a view as a field in another view. Then just build a view for the answers, taking a nid argument as an entity reference contextual filter. And use that view as field in your question listing view.


When you create a node view by default it adds the 'Content: Published (Yes)' Filter Criteria. You must now add a second 'Content: Published (Yes)' filter criteria and set the relationship on it to Answers. And be careful with how you add the relationship initially to bring in the Answer table. If you set it as required then Questions with no published Answers will not be shown.

  • Hi, I have tried this before, but the output is only Question with answers where all of them are published. Other questions with all answers unpublished are not shown.
    – loparr
    Aug 2, 2014 at 15:29

After some hours struggling I decided to use entity reference count module. I did not use it from start, because I was not aware that it has option to count only published nodes - which is exactly what I want. Besides it is better performance-wise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.