How to create a view that filters profiles based on current user's 'interested in' field value? I am working on a small matrimonial application. I've installed the Profile 2 module and added a few fields like 'interested_in', 'gender', 'partner preference', etc to the users of my site.

I need to create a view that will list all profiles with same gender as logged in user's 'interested in' field.

How can this be achieved?
Solution that worked for me:

I used MyModule_views_query_alter hook and added a join to the field table and the condition that matches the choice of logged in user and gender of users in db.

if ($view-&gt;name == 'profile_list') {
        $logged_in = $GLOBALS['user']-&gt;uid;
        $pr = profile2_load_by_user($logged_in,'main');

        $join = new views_join();
        $join-&gt;table = 'field_data_field_gender';
        $join-&gt;field = 'entity_id';
        $join-&gt;left_table = 'profile';
        $join-&gt;left_field = 'pid';
        $join-&gt;type = 'inner';

        $query-&gt;add_relationship('field_data_field_gender', $join, 'profile');

        $view-&gt;query-&gt;add_where(0, db_and()-&gt;condition('field_data_field_gender.field_gender_value', $pr-&gt;field_looking_for['und']['0']['value'], '='));
    }