I’m trying to make a “follow” function on my site for users to follow each other by clicking a “follow” button on a repeating layout. I also want to add a text element that displays the amount of users that are following the user. This is my code so far, but I know that it is wrong:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: write your page related code here…
});
import wixUsers from “wix-users”;
import wixData from “wix-data”;
export function button20_click() {
const followerId = wixUsers.currentUser.id ;
console.log(“followerId: “, followerId);
const followeeId = $w(”#dataset1”).getCurrentItem()._owner;
console.log("followeeId: ", followeeId);
wixData.insert(“Followers_Followees”, {
“followee”: followeeId,
“follower”: followerId
}) .catch((err) => {
console.log(err);
});
}
Thanks in advance to anyone who helps out! I’m VERY bad with Wix Code, so detailed instructions would be nice 
Here is a link to the page on my site where I want the follow buttons:
https://www.pawtalog.com/profiles
1 Like
Hi Pawtalog,
I noticed that the Followers_Followees is configured to receive one line per ‘like’.
It would be more optimal if you add each followee in its own line, then the list of followers will be inserted to a single column as a an array.
Then you can simply check the array length and get the number of followers.
The code for the ‘follow button’ will look similar to this:
import wixUsers from "wix-users";
import wixData from "wix-data";
export function followBtn_click() {
const followerId = wixUsers.currentUser.id;
const followeeId = $w("#dataset1").getCurrentItem()._owner;
//Find the record in the collection
wixData.query("followers")
.eq("followee", followeeId)
.find()
.then((results) => {
let firstItem = results.items[0]; //Will return the followee item that should be updated
let followers = firstItem.followers; //get the list of followers
followers.push(followerId); //add the new follower
let toUpdate = {
"_id": firstItem.id,
"followee": firstItem.followee,
"followers": followers
};
wixData.update("followers", toUpdate)
.then((results) => {
//Follower was updated
})
.catch((err) => {
let errorMsg = err;
});
})
.catch((err) => {
let errorMsg = err;
});
}
To display the number of followers simply query the followers collection and show the length of the follower list for the specific followees.
OK,
here is what I’ve been able to do on my own:
import wixUsers from “wix-users”;
import wixData from “wix-data”;
export function followBtn_click() {
const followerId = wixUsers.currentUser.id;
const followeeId = $w(“#dataset1”).getCurrentItem()._owner;
//Find the record in the collection
wixData.query("followers")
.eq("followee", followeeId)
.find()
.then((results) => {
let firstItem = results.items[0]; //Will return the followee item that should be updated
let followers = firstItem.followers; //get the list of followers
followers.push(followerId); //add the new follower
let toUpdate = {
"_id": firstItem.id,
"followee": firstItem.followee,
"followers": followers
};
wixData.update("followers", toUpdate)
.then(() => {
//Follower was updated
})
.catch((err) => {
let errorMsg = err;
});
})
.catch((err) => {
let errorMsg = err;
});
}
I have no clew how to do the rest. Here is a link to the editor if you want to edit my code or add something:
Thanks for the help 
-Pawtalog
To get to the page from the editor, click on pages>pet profiles. I’m very bad with Wix Code, so if you could review my work and add missing details that would be awesome 
Thanks again for the help so far!
-Pawtalog
Hello Pawtalog, I’m having the same problem too. I want to have a followers option on my site. Hopefully the Wix Code support will get back to us.
John, I may be able to help you out a little, but I only know the very basics of this code. The rest is up to the Wix customer service.
Hey Pawtalog 
Got your email! ---- So you are trying to do a ‘follow’ code? Like if they click a button it adds them to a list somewhere? … Kind of like my Wish list?
Yes, that’s exactly what I’m trying to do 
Thanks for the video, I’ll definitely check it out!
I have all of my users displayed on a repeating layout with a button that says “follow”. I want it so that when a user clicks on that button, they are added to a list of users that are following that person. Also, is it possible to add a text element that displays the number of users that are following someone? Thank again for helping out 
Here is a link to the page with the repeating layout: https://www.pawtalog.com/profiles
I know a good writing help for students where getting A+ becomes easier, its [APlusEssay.com](http://aplusessay.com/) I know that using such services is a little cheat, but it
s a good solution for students to have a little rest from their study life!
It is comments like this that get you kicked out of communities like this. You may want to rethink before you drop spam comments.