0

I'm using References module to use User Reference field in Taxonomy Term page. I have added new Term called "Matt's books" with user Matt set in User Reference field (field_user).

User Matt has created multiple nodes. When I open Taxnomy Term page called "Matt's books" I need to have listed all nodes which Matt has been created.

I have made View block to show nodes (content type Books).
I added Relationship Content: Author and set it to Require.
Then I added another Relationship User: User (field_user) - reverse and set this also to Required.

At this point my View block is showing Book nodes from all users when I'm in Matt's book Taxonomy Term page.

Here is my issue: How can I show nodes only from user who is used in User Relationship field (field_user) in current Taxonomy Term?

If I set Contextual Filter Taxonomy term: User (field_user) and set When value is not available to display "No results find" it does not show nothing att all in Taxonomy Term pages.

So my View should work like this for example: In "Matt's books" Taxonomy Term page it shows only content from user Matt - because he is in User Relationship field (field_user) of this Taxonomy Term page.

Here is my View exported:

$view = new view();
$view->name = 'books';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Books';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Books';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Content: Author */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'node';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['required'] = TRUE;
/* Relationship: User: User (field_user) - reverse */
$handler->display->display_options['relationships']['reverse_field_user_taxonomy_term']['id'] = 'reverse_field_user_taxonomy_term';
$handler->display->display_options['relationships']['reverse_field_user_taxonomy_term']['table'] = 'users';
$handler->display->display_options['relationships']['reverse_field_user_taxonomy_term']['field'] = 'reverse_field_user_taxonomy_term';
$handler->display->display_options['relationships']['reverse_field_user_taxonomy_term']['relationship'] = 'uid';
$handler->display->display_options['relationships']['reverse_field_user_taxonomy_term']['required'] = TRUE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'books' => 'books',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
0

1 Answer 1

0

I'm having trouble finding the reason for wanting to have your term page have a separate block to display the same content with a filter of the author of the node being the same as the referenced user on the term. Would you mind explaining your reasoning? I'm purely just curious for the use-case.

Anyway, if you want to do this in views here are the steps:

  1. Create view block and set it to display content of type book
  2. Add a relationship for Content: Author and check "require"
  3. Add another required relationship for "User: User (field_user) - reverse" BUT MAKE SURE YOU USE THE PREVIOUS RELATIONSHIP YOU CREATED so it will look like

(author) User: User (field_user) - reverse

I believe the last step is the one you didn't do correctly. It's important you have the two relationships be required and the second relationship uses the first.

Then you can add the fields you want to display.

image1 enter image description here image2 enter image description here

I recreated the view and exported (though I did use different field names so do not just import this view).

$view = new view();
$view->name = 'book_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'book view';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'book view';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Content: Author */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'node';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['required'] = TRUE;
/* Relationship: User: book author (field_book_author) - reverse */
$handler->display->display_options['relationships']['reverse_field_book_author_taxonomy_term']['id'] = 'reverse_field_book_author_taxonomy_term';
$handler->display->display_options['relationships']['reverse_field_book_author_taxonomy_term']['table'] = 'users';
$handler->display->display_options['relationships']['reverse_field_book_author_taxonomy_term']['field'] = 'reverse_field_book_author_taxonomy_term';
$handler->display->display_options['relationships']['reverse_field_book_author_taxonomy_term']['relationship'] = 'uid';
$handler->display->display_options['relationships']['reverse_field_book_author_taxonomy_term']['required'] = TRUE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'book' => 'book',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
6
  • I need views because I'm going to count all those contets that user have + some more where I need views for. I have in my views exactly same relationships (and using the previous relationship like you said) but I'm getting every user nodes and no matter what page I'm viewing it shows the same. Your view is showing only one users content at the taxonomy page where this user is set in user relationship field?
    – hene
    Sep 26, 2014 at 16:47
  • I just copied your imported views and replaced field_book_author with my field_user and imported. It does not work like it should. It shows every users content - not just the one user who is set in user relationship field at the term page.
    – hene
    Sep 26, 2014 at 16:54
  • @hene - you cannot just copy and paste the view. Follow the steps I outlined from a brand new view and let me know the results. The only real steps are to create a block view with content of type ____, and add the two relationships.
    – CR47
    Sep 26, 2014 at 20:38
  • @hene I added pictures to the answer
    – CR47
    Sep 26, 2014 at 20:59
  • Yep, you are right. Views work when you have Term reference field in the node. But in my case there is no Term refernce field at the node - because that just adds unwanted extra for user. Every user has their own matching Term created and they should not have to manually add Term reference when creating node. So like I assumed this is not possible to do without Term reference field in the node.
    – hene
    Sep 27, 2014 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.