Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:07:37+00:00 2026-06-02T03:07:37+00:00

When users register they associate to one or more locations via user profile. Location

  • 0

When users register they associate to one or more locations via user profile. Location is a custom content type. I have a custom field in the user profile defining a relation to this location.

I have a user-type view that returns un-authenticated users and is restricted to elevated role users. I’d like to add a filter that only returns un-authenticated users whose associated location value(s) match one or more location values from the current user requesting the view.

I can filter by the associated location, but I can’t relate that value to the current user’s value(s). I feel like I might be able to do this if I could add the current user uid to the relationships area and not just the contextual filters area. Can I do this without resorting to a custom filter or relationship?

EDIT:

There may be some confusion so maybe this will help clarify.

User -> Profile -> Location is the data association chain. I want to only show users whose Location value(s) match those of the currently logged-in user.

User (any) -> Profile (Student) -> Location(s) == User (current) -> Profile (admin) -> Location(s)

I could write SQL to do this but it’s not clear if this is possible to do using views alone, or if I need a custom relationship or filter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:07:39+00:00Added an answer on June 2, 2026 at 3:07 am

    The only way to do this within views is the following:

    1. Make View of using User type
    2. add a Relationship to a Profile2 type (in my case ‘Student’)
    3. Add Contextual Filter of type profile:student:location
    4. select “provide default value”
    5. type: “php code”
    6. Use the following code:

      global $user;
      $profile = profile2_load_by_user($user->uid,'facilitator');
      if (!$profile) { return ''; }
      if (!isset($profile->field_location['und'])) { return ''; }
      $locations='';
      foreach ($profile->field_location['und'] as $location) {
        $locations.=','.$location['nid'];
      }
      return substr($locations,1);
      
    7. Under “More”, Set “Allow Multiple Values” to TRUE
    8. Save your Contextual Filter

    Using PHP in this manner, you can load the current User and get associated values to filter by. This may be useful in many other contexts and circumstances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form where my users can register to my site. They fill
I have a requirement where I have to register users first via email. So,
I have a desktop application. Users register to use it. When they register, I
I have a list of files in the directory C:\Users\Mahady\Desktop\Java 31122011\src\register\ they are like
I would like to allow users register and login so they can access more
I've created an app, I need to have willing users register for a more
I have a site where users can register an account. To do this they
What is the proper way to register users automatically when they log in with
Say a user registers for your site, you hash the password they have chosen
I have a freelance web application that lets users register for events. In my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.