Skip to content
Advertisement

How to get Position of Comment within a Post

So I have a Post which has Comments — I’m trying to get the Comment # position within that post. For example, a Post has 15 comments, I want to be able to get the numerical position (i.e 1 (first post), 2 (second post), 3 (third post), etc, etc), and put this into a function somehow. That way when I can call $comment->position() and it will show as the 4th, 5th, whatever position in it is in.

I’ve done some searching around the web and couldn’t find a solution. Any help is greatly appreciated! This is what I have so far:

JavaScript

Advertisement

Answer

You should first get all your comments as collection.

JavaScript

Then you can search through the collection using the search function and inserting an id you want to search for … or any other param you want.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement