Jump to content

Filtering Results by Number of Comments


Recommended Posts

Hi Guys,

I am running a page template that contains a filter form that allows users to display results based on number of  comments. 

Here is what I am thinking about doing: 

-add new field called total_comments 

-somehow populate this field every time a new comment is added or removed by admin with count($page->comments)

-use form filter to display results that the selector form has found.

Example: $selector = “total_comments>=$q”; 


My question to everyone: Is this a good approach? If so how do I get another field to update based on the comment module adding or removing a comment? 

Link to comment
Share on other sites


I think that you don't need to do that because $page->comments->count return number of comments for page.

Some options to sort pages by comments:

// example: page template "blog-item"
// $pages->find($selector)...

// from top by number of comments
$selector = 'template=blog-item, sort=-comments.count'

// by recent comment
$selector = 'template=blog-item, sort=-comments.created'

// by upvotes
$selector = 'template=blog-item, sort=-comments.upvotes'

Or options by downvotes or stars.
Also, there are and additions, eg. "AND comments.count > 10" etc...


EDIT: read again your question, and if you have page array (results), than you can try to filter results with this:



  • Like 1
  • Thanks 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...