2
votes

In Views, I have an exposed filter that looks at the UID (User ID / Author), but is there a way to limit this to "ONLY" the users who have posted in this content type?

I tried adding a "Content: Author" relationship and hit Apply. I'm not exactly sure why, but it wasn't until this point that I could go back into the relationships and see MORE options, like: "User: Content authored" (which must then be dependent on the first relationship?) so I selected that one too and set it up like so: Relationship step 1 Now I was able to go to the exposed filter and select the relationship:

Relationship step 2 But this didn't work-- the exposed filter continues to show all the registered users.

I also tried putting in a User Reference field (to this content type) and attaching that to a relationship, but it didn't allow anything to show and gave this SQL warning:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_hidden_name.uid' in 'on clause'

How can I limit this author exposed filter to "ONLY" the users who have posted in this content type?

2
The problem is that with the relationship "User: Content authored", you've just added information to your view about the content your users have authored, but there is nowhere to select "content of THIS particular type". So this isn't really limiting your users to authors of a particular type, it's just limiting them to users who have authored ANYTHING when you apply that relationship.Boriana Ditcheva

2 Answers

0
votes

There are a few drupal modules that may help you out. Such as Corresponding node references

However, if you are good with php code, you can create the logic to query the database and return the desired results (which would be the columns of the table). Create a contextual filter, then select a field (any field should work, but best select something in either content type). Then edit it, WHEN THE FILTER VALUE IS NOT AVAILABLE -> Provide default value -> PHP Code

$nid = arg(1);// current node id
$query = "SELECT <desired_field_column_name> FROM {<field_data_table_name>} c 
WHERE c.<column_that_is_same_as_nid> = :nid";                                             
$result = db_query($query, array(':nid' =>$nid));
$id = array();
while ($row = $result->fetch())
{
                array_push($id, $row->field_curator_target_id);//put each node id that's referenced in array
}

$separated = implode("+", $id); // separate them by + for AND , for OR
return $separated; //eg.32 + 30 would represent nodes that you want.
0
votes

In Linked theme there is answer about Views Selective Filters (aka "Views Selective Exposed Filters", aka views_filters_selective, aka views_selective_filters).

This module adds filters that have suffix "(selective)" in their names – add one you need instead of filter w/o the suffix.