2

I have a Views block that has the intention to display all nodes that share the same parent term.

For example:

  • Queensland
    • Cairns
    • Brisbane
    • Gold Coast
    • Port Douglas

If I'm on the Cairns page, then it will show all the children of Queensland. The problem with this is, I need to exclude Cairns, as I'm already on this page.

I already tried the solution from "How to list similar products using views in Commerce Kickstart?", but it didn't work. I had an issue where the query preview wouldn't even show, even though I entered the term ID to attempt to get the query.

Any ideas why this would happen?

Notes:

  • I already entered the term ID to update the preview, but it didn't show anything. If I take the nid filter out, then it works fine, with the caveat that it shows the current page in the results.
  • I notice something weird where checking exclude in the nid contextual filter shows all the results including Cairns, yet when I uncheck it, then all the results disappear. Is there a reason this would happen?

3 Answers 3

1

Query Preview will not be show when you add contextual filters.

You will need to add 'nid/termid' in "Preview with contextual filters:"

In short, Contextual filters will take nodeid/termid from URL.

enter image description here

5
  • Sorry forgot to mention that above. I already entered the term ID to update the preview, but it didn't show anything. If I take the nid filter out, then it works fine, with the caveat that it shows the current page in the results. Commented Oct 27, 2016 at 12:04
  • As per the link you provided you need to add two filters -> termid/nodeid. Example: 2342/6666
    – NTT
    Commented Oct 27, 2016 at 12:06
  • I see what you meant now by having the 2 filters added in i.e. nid/tid. I can confirm that a query was sent back, but I still have the issue where Cairns is showing in the results. Commented Oct 27, 2016 at 12:53
  • If you can play around with that node id contextual filters, I am sure you will get the result.
    – NTT
    Commented Oct 27, 2016 at 12:56
  • Noticing something weird where checking exclude in the nid contextual filter shows all the results including Cairns, yet when I uncheck it, then all the results disappear. Is there a reason this would happen? Commented Oct 27, 2016 at 13:40
0

Oops. I had the same kind of issue last year, making this site: http://notonlymakeup.net

There are two steps (as I see you are on the right track):

  • Add a contextual filter for taxonomy term: Use default value as taxonomy term ID from content being displayed on the page. After this step, you should be able to see all related nodes which share the taxonomy term field you chose to apply the filter on.
  • Add contextual filter for the node being diaplayed: Use default value as content id from the url. This would help you exclude the node being viewed.

Here is a video tutorial: https://www.daymuse.com/blogs/drupal-guide-related-content-term-views

If the tutorial does not help, please export your view and share it with us so that we can try to recreate the scenario and help you figure out what's going wrong.

0

Thanks for getting back to me with your answers.

In my case, it turns out that, as my view had a sort criteria set for weight of the node, I had to make sure that all the relevant nodes had a unique value for weight set (hope that makes sense!). As this was displaying only nodes for one content type, this ended up being a relatively easy fix.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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