I have Views block that displays one image from a current node, but some nodes dont have image in that field and I want to use image from another node with the same taxonomy term as currently viewed node.
I can use contextual filters for that, but two filters (first by NID, second by taxonomy term) not work correctly, only the first one is used.

Is there any way to resolve that problem by standard views features or I should install additional module like views_contextual_filters_or?

Comments

pixelsweatshop’s picture

You will want to create two views. Do the first as you have done above and the second will contain the contextual filter for the term. Then go back to your first view and under "No results behavior" add Global: View area
Insert a view inside an area. Add reference to your second view.

bigfatguy’s picture

Great. Thank you!

pixelsweatshop’s picture

Actually thinking about it a bit further, you can do this with just one view. Setup the view as you did in the first place, then add the relationship to the taxonomy. Then on your field settings add the taxonomy image field and set to hide from display. Then add the image field from the node, set to when empty show the image field from your taxonomy using the token.

bigfatguy’s picture

Problem is that image file is located in the same field for both conditions.

pixelsweatshop’s picture

Not if you specify the relationship in the field's settings.

bigfatguy’s picture

When I add second image content to a "fields" I dont see any relationship dropdown list inside that field settings to select previously created relationship in "advanced" section. May be some module is missing that is required for that functionality?

pixelsweatshop’s picture

Is your taxonomy reference via a taxonomy field or an entity ref field. You may have selected the wrong relationship.

bigfatguy’s picture

Yes, previously I've selected wrong relationship (content: taxonomy).

Now all seems correct:

Relationships > Taxonomy term: Content using Tags. Not Require this relationship

Relationships > Content: Taxonomy terms on node. Vocabulary: Tags, Identifier: Term. Not Require this relationship

Contextual filters > Content: Nid > Do not use a relationship > Provide default value > Content ID from URL

Fields > Content: Image. Relationship field_tag_single. Exclude from display

Fields > Content: Image. Do not use a relationship. No results > [field_image_2]

But now this views block displays nothing at all... Never used relationship feature before, some may be I've missed some obvious settings.

pixelsweatshop’s picture

Relationships > Taxonomy term: Content using Tags. Not Require this relationship

Relationships > Content: Taxonomy terms on node. Vocabulary: Tags, Identifier: Term. Not Require this relationship

I don't think these are the relationships you want. Are you using a term ref field or an entity ref field to add the taxonomy?

bigfatguy’s picture

In each node I use term ref field.

pixelsweatshop’s picture

Ok. Don't use the taxonomy relationships you mentioned above. Filter the relationships by "content" and choose the the actual field that references the taxonomy.

bigfatguy’s picture

That was what I've originally made, but with that type of relationship I dont see dropdown list on field.