2

I am trying to create a view to filter content types assigned to a specific country (set using Address Field module), determined by the current node's title.

My address field is not being listed under relationships in views.

How am I able to set contextual filters by a nodes country? Is this currently possible, or am I just missing something?

1 Answer 1

1

The country should be filtered by the current node's title

The better approach is to create Taxonomy Terms, so you can tag your nodes.

In admin/structure/taxonomy Add a vocabulary called Countries.

Then add a term reference field to your content type and select countries as your vocabulary, and use auto complete widget.

So all you have to is type the country name here and it will tag your node with that name.

In views, for contextual filter add Has taxonomy term ID

enter image description here

PS: You could use the Rules module to auto tag your nodes based on the Country field value.

6
  • I am able to follow the steps you have above, however I do not wish to expose this option to users. The country should be filtered by the current node's title (Which will be the name of a country). My view is of the type "Content". Are you able to see Address Field fields (such as country) under the relationships tab? Once again, thank you very much for your help.
    – BokBok
    Commented Sep 2, 2016 at 22:23
  • Are you able to see Address Field fields (such as country) under the relationships tab? Nope, nothing with country shows up here. Furthermore, when I try to contextual filter by country nothing shows up, seems to me that this module is buggy.
    – No Sssweat
    Commented Sep 2, 2016 at 22:40
  • Yep, that is what I think aswell. I will try and get in touch with the developers of the module and see if I can find a solution. Thank you very much for your help.
    – BokBok
    Commented Sep 2, 2016 at 22:44
  • I discovered something, the contextual filter works with two character country code. So instead of United States, you put US
    – No Sssweat
    Commented Sep 2, 2016 at 22:46
  • 1
    Thank you! The above answer sounds like it will work perfectly. I really appreciate all your help!
    – BokBok
    Commented Sep 3, 2016 at 9:17

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.