5

I have installed the Flag module, and I have a view that displays how many followers (flags) an author has. How do I reverse that query, and output how many users that author is following?

1

This is a little tricky, but it is very similar to the article posted at http://drupal.org/node/326580.

  • Create a view of users
  • Add the "Flags: User flag" relationship making sure that the flags are by any user.
  • Add the "Flags: User" relationship which will allow us to filter by the person who did the flagging.
  • Add a contextual filter (D7) / argument (D6) fir the "User: Uid" and make sure is uses the "Flag user" relationship.
  • In contextual filter / argument, select the "Provide default value" option and add the following code snippet to pass the node author as the value.

Code snippet:

if ($node = menu_get_object()) {
  return $node->uid;
}

In order to get the count it will depend on whether you are using Drupal 6 or Drupal 7, but using the Views Group By module for D6 or the internal Aggregation features of D7 should be able to get you the number of users.

4
  • Chris- thanks for the response! I am using D7.4- can you explain more about what you mean by 'internal aggregation features of D7"? I don't know how to do that. I have been banging my head against the wall for weeks trying to figure this out! This is the closest I've seen to any solution. THANK YOU!
    – user800507
    Jul 16 '11 at 21:19
  • Likewise- that Views Groupby Module will not install into version 7. It says it is incompatible. There is no version for D7. Any other suggestions?
    – user800507
    Jul 16 '11 at 21:26
  • ok- I followed this exactly as you say. I have a block I was adding this into that was working as well- showed # of followers the author had. However, when I follow your instructions exactly as you state- it makes the block disappear. That's with both adding in the Grouping field, or leaving it out. Any suggestions? Again, thanks for the help!
    – user800507
    Jul 16 '11 at 21:41
  • Holy crap this is a tricky problem! I've made a blog post about it for D7: leesome.com/blog/2013/02/18/… Basically reversing the output has to do with linking or not linking the uid Contextual Filter to the relationship
    – CamelBlues
    Feb 18 '13 at 22:08

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.