I'm currently using User relationships module, and setting the UR-Node access module so that nodes can only be viewed by users related to the author.

However, I want to have a public display version of the node for search engines, sharing links, and also for a button to say 'You need to become friends with x to see this node'.

So, I was thinking of using the User relationships API to determine the users' relationship, and output two different displays in the tpl.php file.

Does anybody know how to determine the relationship programatically? I'm stuck.

(I've done this in the Views I've made, it's just in the nodes, that I'm having trouble)

2 Answers 2


It looks like you can use the user_relationships_load() function. The following code will load all relationship objects that exist in the system between 2 users. From there you can inspect the relationships for their type/properties and make your decision based on that:

// Set up the user ids
global $user;
$current_user_uid = $user->uid;
$node_author_uid = $node->uid;

// Set up the parameters
$params = array('between' => array($current_user_uid, $node_author_uid));

// Get the relationships
$relationships = user_relationships_load($params);

Here is a sample code to check relationship:

you should replace friend with your relation type

$relations = user_relationships_load(array('between' => array($node->uid, $user->uid)));
$are_friends = FALSE;
foreach ($relations as $relation) {
  if ($relation->name == 'friend') {
    $are_friends = TRUE;

if ($are_friends):
//do something 
//do something else

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.