Forum Academy Marketplace Showcase Pricing Features

Sorting repeating groups by Likes


I’d like to create a “Top Posts” section, for the top user-submitted articles of the day. How can I do this?

I’d also like to create a “Post of the Day” feature. How can I grab the top article of the day and display it?

1 Like

I take you have some way to count what’s a top post. So you should be able to sort on that and retrieve the first one or a fixed number of them in a Repeating group.

Cheers, Peter

The way I’d approach it is below. I’m not a Bubble expert though, so there may be a better way.

Step 1: In the User datatype, have a list field for Liked Posts. When a user “likes” a post, the workflow adds the post to the User’s list of Liked Posts.

Step 2: In the Post datatype, have a number field for “Likes”. Have the above workflow add +1 to the “Likes” field when a user likes a post.

Step 3: Sort the RG of posts based on the Likes field.

Ideally, you could have Bubble “:count” the number of Liked Posts in Step 1 above, and therefore you wouldn’t need Step 2. But I have not run across any way of sorting based on real-time calculated fields within native Bubble. Doing that would require a plugin.

You could also run a back-end workflow that runs regularly to count all the likes and assign that number to the posts field, but the above method seems simpler to me.

1 Like

I’m trying to do the same thing. I have “likes” as a field associated with the relevant data type and when a user clicks “like”, it adds +1 to the count of that data item.
However, I am trying to create a list of “top posts” too, that displays a list of the data and sorts them by count of # of likes.
In repeating group, I have:

Search for [data type]:sorted by dynamic field

and then in the List Sorting Order popup, it provides an option to “Sort By”… and it lists a few of the fields associated with the data type. However, “likes” is not listed as an option. Why is this?

Thanks for anyone who can help my with this!

First, is the “likes” field of type number? If not, then that might be the reason. Why not also try using the direct sort inside the “search for” dialog box.


something like that.

“likes” field type was initially “list of users”. Thanks to you, I learned this won’t work. You can’t sort by a count of how many items in the list.

So I deleted that field, and created a new one called “likes2” with type “number”.

…and it worked! Once the field is type number, it displays in the list of “sort by”. And so, if you want content with the most likes to appear at the top, you would say sort by descending to “yes”.

Thanks for the help and assistance on this resolution!

1 Like