Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The taxonomy_index table does not contain entries for unpublished nodes.
Steps to reproduce:
1. Tag published and unpublished nodes with term.
2. Create content view, no filters, add contextual filter "Has taxonomy term ID" or "Has taxonomy term ID (with depth)"
3. Preview with term in (1), note only published nodes get returned
Comment | File | Size | Author |
---|---|---|---|
#4 | Captura de Tela 2016-11-28 às 16.10.37.png | 135.01 KB | cesarromagnolo |
#4 | Captura de Tela 2016-11-28 às 16.05.01.png | 45.5 KB | cesarromagnolo |
Comments
Comment #1
babusaheb.vikas CreditAttribution: babusaheb.vikas commentedHi tbfisher,
Install Taxonomy Entity Index module, visit admin/config/system/taxonomy-entity-index to rebuild the Taxonomy Entity Index.
Note that in Views there will be some new fields/filters to work with, for instance instead of Content: Has taxonomy term ID in filters section of views, you would use "Taxonomy Entity Index: Has taxonomy term ID on Content (with depth and indexed in taxonomy_entity_index)".
In this way you will found all published and unpublished nodes related with the term ID.
I hope your problem will fix.
Comment #2
feldmarv CreditAttribution: feldmarv commented@babusaheb.vikas
thank you very much, your post helped me a lot!
Comment #3
joseph.olstadMy client wants to see unpublished content on views when logged in, trying to set this up and came accross an issue with the taxonomy term not wanting to play nice with unpublished content, making it impossible to have a context relationship to a term from unpublished nodes. Only published nodes are playing nice with taxonomy terms.
Going to investigate the described workaround.
Comment #4
cesarromagnolo CreditAttribution: cesarromagnolo at CI&T commentedI able to reproduce this bug, but this is not a bug of views.
The SQL that the views has construct to filter the node is based on table "taxonomy_index".
Example:
But in taxonomy.module (core) has a hook "taxonomy_build_node_index" that create a record on table taxonomy_index only if the status was published.
In this case, the views is filtering correctly, the bug probably is on taxonomy.module.
I don't know why the core do this, i will not modify.
Comment #5
joseph.olstadOk, there's probably a patch for core that fixes this, please look at the drupal core queue for 7.x and follow up with the patch that fixes this, we can change this ticket to a 'support' request and mark it as a related issue to the other issue once we find it.
Comment #6
joseph.olstadThere's an issue in core for this, I'll take a stab at backporting it to D7 as it's not yet in any release.
Comment #7
MustangGB CreditAttribution: MustangGB commentedComment #8
joseph.olstadI got this working in D7 by backporting the D8 core patch.
see #2878046: D7 Taxonomy Index for unpublished entities
we've been using this for quite some time in conjunction with "Views Published or Role"
Comment #9
MustangGB CreditAttribution: MustangGB commentedCool, lets go with #2878046: D7 Taxonomy Index for unpublished entities then.
Comment #10
joseph.olstadComment #11
joseph.olstad