2

How does one create a view that filters users so as to display those with preferences of the logged-in user (the one viewing them)? I'm using Drupal 7.34, Views 3.

E.g. A user selects a preference on sign up, such as "i'm interested in a man". How do you create a view that will show this user a list of users who selected "I'm a man" on their own signups. Think of it as matchmaking.

I came across this discussion but didnt figure out this comment. All the articles out there don't seem to address this clearly.

I'm certain there is a contextual filter move I'm missing. Please help.

1

I had same issue but solved by using this custom code in view. I was using profile2 module for registration so as per sex field, I was done this :

global $user;
$profiles = profile2_load_by_user($user);
foreach ($profiles as $profile) {
  if ($items = field_get_items('profile2', $profile, 'field_seeking')) {
    break;
  }
}
   return $items[0]['value'];

Please check my Post HERE.

As per my post I was do this :

global $user;
    $profiles = profile2_load_by_user($user);
    foreach ($profiles as $profile)
    {
        if ($items = field_get_items('profile2', $profile, 'field_sex'))
      {
            break;
          }
    }

    $i_am=$items[0]['value'];

    if($i_am=='sdmale' || $i_am=='sbmale')
    {

    $looking='smfemale+sbfemale';
    }

    if($i_am=='smfemale' || $i_am=='sbfemale')
    {
    $looking='sdmale+sbmale';
    }
    return $looking;
  • Where in View did you enter this custom code?I'm using core profile, not profile2. – EpicNet Dec 30 '14 at 7:38
  • Enable PHP Filter module & you'll get an option in view & add your code there. – Nishant Dec 30 '14 at 10:25
  • Despite activating those modules, and adding the code with few adaptations nothing is happening. I'm new at coding php. Should I put only field in "field_get_items" when in reality drupal is supposed to manipulate data from 2 fields and from 2 different users in any single session? – EpicNet Dec 30 '14 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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