In my user profile I use a custom field named field_country, which is actually a list of countries. (like descibed here: http://drupal.org/node/35728)
This field is part of the registration process.

Now I'd like to set up a view getting all nodes submitted by authors/users from the country they selected.

I think, that should be done with Views >> Arguments, but the custom profile fields are only available within Views >> Fields.
Next idea is using some custom code as Argument Handler Code, but code I but in there seems not to be executed.

Any ideas how to do something like this?

Thanks

Comments

joshua_cohen’s picture

track

suit4’s picture

Drupal is so cool!

This is simple!

The node type I use is custom cck, let's call it 'Project'.
Just add a new cck field to the 'project' node, the type should be 'computed'! (Yes, you need the module for cck computed fields! See http://drupal.org/project/computed_field)

Set the label to 'Country'.
In Data Settings set to 'Required' and put in

// Load author details
$author = user_load(array('uid' => $node->uid));
$node_field[0]['value'] = $author->profile_country;

I'm not shure about the other settings,
I use
Display: yes

$display = $node_field_item['value'];

Store using the database settings below: yes
Data type: text
Data Length: 256
Default: Empty
Not NULL: yes
Sortable: yes

Now, you can go to the views and create a view with 'field_country' as argument, now it is present there.

whereisian’s picture

Very helpful snippet. Cheers!

gotcha41’s picture

Here you need to do this for every Custom Profile Field, right? Is there a way to have this done automatically, so for any custom field you create?