I'm running a D7 system Where users can follow each other using 'Follow' flag on user's profile.

Now I've been assigned a task to come up with a view where I can have a list of content posted/commented by people I follow.

I tried so many ways but no luck.

  • Are you using the Flag Follow module? Hearbeat running good? If not, how did you create the follow flag? Just a custom field?
    – Lauro S.
    Commented Jul 29, 2015 at 14:52
  • Are you looking for the content "types", or the actual "nodes" with these content types? Also, can you enhance your question to provide more details about the "so many ways" you tried. That may help to provide you an accurate answer ... Commented Jul 29, 2015 at 14:52
  • @LauroSollero, I'm using normal 'Flag' which is then attached to 'user' entity type.User profile is laid out using panels.
    – Ozyy
    Commented Jul 29, 2015 at 14:57
  • @Pierre.Vriens, my D7 system has quite a few content types like news, blog, galleries and so on. What I want is a list of all of the nodes which were published or commented by the people I follow keeping in mind 'follow' is flag on user profile.
    – Ozyy
    Commented Jul 29, 2015 at 15:00
  • Did you try this solution drupal.org/node/1580762 ?
    – Andrew
    Commented Jul 29, 2015 at 15:50

2 Answers 2


Humm, I couldn't find a way to easily put them all together (comments and nodes authored by the users followed) but could create separate views.

For nodes created is easier: Create a new View, change from Show Content to Show Users and in the Relationship add a Flags: User flag, choose your flag and Current user.

For comments created: Create a new View, select Show Comments. In the Relationship add Comment: author to expose the Authors ID, select require this relationship. Add new Relationship, this time look for Flag: User flag, select the author's relationship created before and your flag.

As stated before, you might get all the content together but I couldn't get it in any easy way.


I've achieved this with the help of contextual filter content: nid and then using custom php which is below

 global $user;
$flag_items = flag_get_flag_flagging_data('Your_flag_name');
foreach($flag_items as $flag_item){
 if($flag_item->uid == $user->uid){
   $uids[] = $flag_item->entity_id;
$nids = '';
$result = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('uid', $uids, 'IN')
while($record = $result->fetchAssoc()) {
  $nids .= $record['nid'] . '+';

$result = db_select('comment', 'c')
    ->fields('c', array('nid'))
    ->condition('uid', $uids, 'IN')
while($record = $result->fetchAssoc()) {
  $nids .= $record['nid'] . '+';
$nids = trim($nids, '+');

return $nids;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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