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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

babusaheb.vikas’s picture

Hi 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.

feldmarv’s picture

@babusaheb.vikas
thank you very much, your post helped me a lot!

joseph.olstad’s picture

My 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.

cesarromagnolo’s picture

I 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:

SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, 'node' AS field_data_body_node_entity_type
FROM 
{node} node
INNER JOIN {taxonomy_index} taxonomy_index ON node.nid = taxonomy_index.nid
WHERE (( (node.type IN  ('page')) AND (taxonomy_index.tid = '6') ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0

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.

joseph.olstad’s picture

Category: Bug report » Support request

Ok, 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.

joseph.olstad’s picture

Version: 7.x-3.11 » 7.x-3.14
Priority: Normal » Major
Parent issue: » #962664: Taxonomy Index for unpublished entities
Related issues: +#1182924: Unpublished entities do not appear in views when using a taxonomy relationship

There'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.

MustangGB’s picture

Priority: Major » Normal
joseph.olstad’s picture

I 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"

MustangGB’s picture

Status: Active » Closed (duplicate)
joseph.olstad’s picture

joseph.olstad’s picture