gerritvanaaken Posted January 11, 2018 Share Posted January 11, 2018 Hi there! I need to gather a list of all comments, regardless of the parent page of each comment. Is there a global $comments object, which can do this? Something like: foreach($comments->find('sort=-created') as $comment) { // show comment } I did not find anything similar in the forums. Can someone help me? Link to comment Share on other sites More sharing options...
gerritvanaaken Posted January 11, 2018 Author Share Posted January 11, 2018 I came up with a pretty "close-to-the-metal" solution. Not perfect, but seems to work: $comments = $database->query('SELECT * FROM field_comments ORDER BY created DESC'); foreach($comments as $c) { // $c is an array with raw database values of those comments } Link to comment Share on other sites More sharing options...
louisstephens Posted January 11, 2018 Share Posted January 11, 2018 Not tested, but you could search by template(s) and doing something like: <?php $replies = $pages->find("template=your_template"); foreach ($repliess as $reply ) { foreach ($reply->comments as $message) { # code... } } ?> Link to comment Share on other sites More sharing options...
gerritvanaaken Posted January 11, 2018 Author Share Posted January 11, 2018 @louisstephens Thank you for your thoughts! Sure, I could use these "nested" queries to gather a "global comments array", which I would to sort by "created" afterwards. But these are too many steps and seems not very performance efficient. Link to comment Share on other sites More sharing options...
flydev Posted January 11, 2018 Share Posted January 11, 2018 this should work : $field = $fields->get('comments'); $comments = $field->type->find($field, "sort=-created"); 6 Link to comment Share on other sites More sharing options...
gerritvanaaken Posted January 11, 2018 Author Share Posted January 11, 2018 @flydev Awesome, works like a charm! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now