QUESTION
I have an address field in my user form, from the address field module.
I have a content type named "project" which also have an address field and users can pick up a country related to the country the project will belong to.
I want to make a view filtering all the projects related to the logged-in user's address country field.
TRY
My trick is to make a user-view with a author-content relationship filtered on the content type project. Now I have the two fields in the view, I'm trying to compare them with a contextual php filter.
I tried to use php filter based on this post
$node = node_load($data->nid);
$user = user_load($user->uid);
$field_user_country = field_get_items('user', $user, 'field_user_address_country');
$country_user = field_view_value('user', $user, 'field_user_country', $field_user_country[0]);
$field_project_country = field_get_items('node', $node, 'field_project_range_country_country');
$project_country = field_view_value('node', $node, 'field_project_country', $$field_project_country[0]);
if ($price_a = $price_b) {
return TRUE;
}
The fact is field_user_address_country is actually stored under field_data_field_user_address in the database.
Same for field_project_range_country_country which is stored under field_data_field_project_range_country
What is the best way to do this ? Is what I'm trying to do possible ?
UPDATE 1
Clear code which give me an ajax error :
$node = node_load($data->nid);
$user = user_load($user->uid);
$field_user_country = field_get_items('user', $user, 'field_user_address_country');
$country_user = field_view_value('user', $user, 'field_user_address_country', $field_user_country[0]);
$field_project_country = field_get_items('node', $node, 'field_project_range_country_country');
$project_country = field_view_value('node', $node, 'field_project_range_country_country', $field_project_country[0]);
if ($country_user == $project_country) {
return TRUE;
UPDATE 2
Here the new code which is still giving me an ajax error :
EntityMalformedException : Missing bundle property on entity of type node
$node = node_load($data->nid);
$user = user_load($user->uid);
$field_user_country = field_get_items('user', $user, 'field_user_address_country');
$country_user = field_view_value('user', $user, 'field_user_address_country', $field_user_country[0]);
$field_project_country = field_get_items('node', $node, 'field_project_range_country_country');
$project_country = field_view_value('node', $node, 'field_project_range_country_country', $field_project_country[0]);
if ($country_user == $project_country) {
return $country_user;
}
Have a bigger ajax error (like 15 lines) if I put
global $user
$node = ($node = menu_get_object()) ? $node->nid : NULL;
At the beginning of my code.
if ($price_a = $price_b) {
here you are setting $price_a equal to $price_b rather than checking if $price_a is equal to $price_b. You need to use==
when performing checks. So this needs to beif ($price_a == $price_b) {
if ($country_user == $project_country) {
also fix remove 1$
from$$field_project_country[0]