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 – J. Reynolds Jan 27 '15 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 '15 at 8:55
  • If you aggregate correctly you should get it right. – J. Reynolds Jan 27 '15 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 – J. Reynolds Jan 27 '15 at 17:03
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 '15 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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