0

We have a Question and Answer setup on Drupal. Question is a node. The answer is a comment.

What we are trying to do is to order Questions by either the latest asked question or by the latest commented question.

So when a new comment it posted, that questions moves on top. I can do it for Question or comments. But can't combine the two together.

Is there any way to achieve this?

1 Answer 1

1

If you were building the SQL directly, you could do it in the ORDER BY clause with the CASE WHEN syntax where you do something like:

CASE WHEN comment_table.timestamp > node_table.timestamp then comment_table.timestamp else node_table.timestamp

Since there is no default Views core plugin for CASE WHEN sorting, you can either build a Views sort plugin that implements the syntax or use existing plugins that allow custom SQL with a notable security caveat that comes with storing code in your configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.