1

I have a views of unpublished contents of content-type X, which has the Term Y.

It works fine with published content but a thing that I noticed is that if I unpublished a content that has a taxonomy term, in Views it loses the term associated with it, therefore I cannot filter my list based on taxonomy term anymore.

I also found Taxonomy Entity Index module but it doesn't work at all.

Also a related issue on drupal.org

Is there any workaround for this?

3 Answers 3

3

"Lookup published nodes with this taxonomy term" is such a common use-case that the Taxonomy module keeps a taxonomy_index table in the database to optimize for it. This is what the Content: has taxonomy term ID views argument queries. Unfortunately, it is only for published content.

In Drupal 8, there is a workaround. Taxonomy term fields are just a special case of Entity Reference fields, which have their own views argument handler, and do not partake of this special index. So, if Content-type X has a 'Tags' field, you can build a view based around Content: Tags (field_tags), and that will include unpublished content as you'd expect.

1
  • This is what helped me - to filter by a field in my content type that uses taxonomy term as entity reference. Thanks!
    – aek
    Feb 7, 2018 at 17:17
1

For anyone who might encounter the same issue:

It looks like that it's a common issue in D7 and unfortunately going to be in D8, but hopefully the fix will be in core for D9.

Right now we have to use TEI module as a workaround for D7 and D8.

If you are installing this module into an existing site, visit admin/config/system/taxonomy-entity-index to rebuild the Taxonomy Entity Index.

Also note that in Views there will be some new fields/filters to work with, for instance instead of Content: Has taxonomy terms in filters section of views, you should use Taxonomy Entity Index: Has taxonomy terms on Nodes and for exposing the taxonomy terms also you should use Taxonomy Entity Index: Has taxonomy terms on Nodes not the default Content: Has taxonomy terms.

2
  • Sohail wrote "Right now we have to use TEI module as a workaround for D7 and D8." But here: TEI module; I see that there is only drupal 7 and not drupal 8. Sep 3, 2016 at 2:12
  • For D8, the TEI module isn't ready to use in prod.But @SeanC tips work.
    – user8753
    Nov 15, 2019 at 10:36
0

On Drupal 8 :

  1. Apply the patch from this issue
  2. Clear cache : drush cr
  3. Updade database : drush updb

It works for me.

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.