Hi,

Not sure if this is by design or a bug but I have the following problem:

I have a multivalue field (let's call it "List Field") that I use to store a list of NIDs. When using Views I use a Contextual Filter ("List Field") with "Exclude" checked to keep any Node with a value in the "List Field" that matches a component of the URL from displaying. My filter works fine if the "List Field" only contains 1 value but it does not work if the "List Field" contains more than 1 value unless all of the values in "List Field" are passed to the filter. For Example:

This works:
"List Field" Values:
2054
Filter input:
2054
This works and the Exclude works.

This does not work:
"List Field" Values:
2054
3021
Filter Input:
2054
In this case the Exclude does not work and the Node is still displayed.

Without the Exclude box checked both examples above work to limit the View.

Any help will be greatly appreciated.

Thanks!

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Yuri’s picture

I confirm that this issue is present.
In my case I use OG groups audience, which also is a multi-value field.
When I exclude the current group by using the 'exclude' checkbox in the contextual filter setting, only group content with the current group as single group audience is excluded, but still group content is shown that have the current group and other group(s) as group audience.

By the way, I do'nt see a workaround either.

Luukyb’s picture

Experiencing a similar issue here.

nimoatwoodway’s picture

same issue here with an entity reference field and multi-value. Any idea how to fix this?

diego.husu’s picture

If somebody needs this, i've used a simple solution for this bug.

I added in a hook_views_query_alter a specific condition for excluding nodes that have that value in one of the occurence of that field.

I found indexes debugging the query, so pay attention with that.

If someone has a better solution please post it :)

function MYMODULE_views_query_alter(&$view, &$query) {
    if($view->name == 'MY_VIEW_NAME' && $view->current_display == 'MY_VIEW_DISPLAY') {
        $query->where[0]['conditions'][] = array(
            'field'=> 'node.nid NOT IN (SELECT entity_id FROM tbl_field_data_FIELDNAME WHERE FIELDNAME_value = :field_data_FIELDNAME_value)',
            'value' => array(':field_data_FIELDNAME_value' => $view->args[0]),
            'operator' => 'formula',
        );
    }
}
annya’s picture

I have the same problem with taxonomy terms. In my case everything works great with filters, but doesn't work with contextual filter. As for me they should have the same API, but different sources and configuration. I'm not sure why, but filters and contextual filters have different implementation and query handling. Anyway, I'm not sure if this is a problem or it works as designed.

This is fix for taxonomy term. I will appreciate for review.

drunkencelt’s picture

#4 worked for me but only once I changed the line

tbl_field_data_FIELDNAME WHERE FIELDNAME_value = :field_data_FIELDNAME_value)',
to
field_data_FIELDNAME WHERE FIELDNAME_value = :field_data_FIELDNAME_value)',

as I was getting table does not exist errors when configuring the view.

Thanks for the post.

ConradFlashback’s picture

+1
Problem with entityreference multiple field.
I will try the #4 solution, but this is a little bug.

ConradFlashback’s picture

Status: Needs review » Active
stiml’s picture

I have the same issue with contextual filter "Content : NID"

My solution bellow, you can replace $args array by $args URL.
I hope that help you.

function MYMODULE_views_query_alter(&$view, &$query) {
    if($view->name == 'VIEW_NAME' && $view->current_display == 'VIEW_DISPLAY_ID') {
        $args = array('1', '2');
        foreach($args as $nid){
            $query->add_where_expression('AND', 'node.nid != :node_nid', [":node_nid" => $nid]);
        }
    }
}