2

There is a content type has a Field Collection type field(multi value), this Field Collection has a date field, I want to sort the node according to the max date value in this Field Collection field(multi value) in views, how to custom this views sort handler.

4
  • 2
    Sounds like your sort needs to aggregate on max Jan 27, 2015 at 4:11
  • Yes, but I have a multi value term reference field in this view, if I open the aggregate, this field will let the view result duplicate, so a little conflicting. Is it possible to do by custom sort handler?
    – waveer
    Jan 27, 2015 at 8:55
  • If you aggregate correctly you should get it right. Jan 27, 2015 at 14:18
  • If you add the term reference just as the field, then group on the term reference as follows: Aggregation type: Group results together, Group Column: Entity ID Jan 27, 2015 at 17:03

1 Answer 1

1

Use aggregate and set the option for distinct results. Aggregate is similar to GROUP BY in SQL so be careful what fields you include. If you really need to do it with custom code set a tag for your view's query in advanced settings and then use this tag to alter your query by implementing hook_query_alter or hook_query_TAG_alter in a custom module https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_query_TAG_alter/7

1
  • Thanks for your answer, I can do it in view now, but I will also check the hook_query_tag_alter.
    – waveer
    Jan 28, 2015 at 2:41

Your Answer

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

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