WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At the moment my users posts are only viewable to them. I would like to implement a system where they can choose to share any post with other users they know. The problem I'm having is, how do I make the connection between users?

The best I came up with is to create a table in the db and store their friends by user id's. Example:

user_ID 2   friends_ID 5,9,34,85

user_ID 87   friends_ID 67,2,99,100,58,309

I want to be able to retrieve their friends list so I can use it later in various parts of the site.

I know this will not be simple, but I am fully open to ideas, suggestions or similar plugin. Thank you all in advance.

share|improve this question
I think you're asking for quite a lot of code here. Either break it down, and ask questions along the way, or you could consider wpquestions.com to pay someone to do it!! – Mild Fuzz May 3 '11 at 12:04
I am not asking for code, I am asking how would you go about setting up the friends in the db? – Holidaymaine May 3 '11 at 18:14
up vote 5 down vote accepted

BuddyPress can be used as a framework - it allows you to friend other users, and is a good place to start from.


This is the structure of the BuddyPress friends table (bp_friends)

CREATE TABLE `wp_bp_friends` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `initiator_user_id` bigint(20) NOT NULL,
  `friend_user_id` bigint(20) NOT NULL,
  `is_confirmed` tinyint(1) DEFAULT '0',
  `is_limited` tinyint(1) DEFAULT '0',
  `date_created` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `initiator_user_id` (`initiator_user_id`),
  KEY `friend_user_id` (`friend_user_id`)
share|improve this answer
That's available at buddypress.org, FYI, or just search on BuddyPress in the plugin installer inside of WordPress itself. – ZaMoose May 3 '11 at 13:36
Thank for your suggestions anu & ZaMoose, but I have considered using Buddypress and it has many features I don't want and it will need to be heavily modified to work with my already existing sits. Instead of modifying Buddypress and mysite I can take the time to build a system myself and get all the features I need. I am just look for ideas on the best way to store the data as I have little experience working with databases. – Holidaymaine May 3 '11 at 18:24
I've updated my answer with the structure of the BuddyPress friends table – anu May 3 '11 at 20:50
Thank you again anu. I was just about to dig through BP to see how they are doing it. Thanks. – Holidaymaine May 3 '11 at 21:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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