2

Im pretty new with advanced views and references module (Drupal 7). Im seeking for some help.

I would like to sort nodes based on node post date of the nodes that references it. So I have node type A and node type B that can reference node type A (A-one, B-many). I would like to sort type A nodes based on which has the latest Type B node.

Almost like journals that can have posts and I would like to see a list of the journals that have the newest posts.

Any idea how to approach this correctly, I seem to struggle and get some odd results.

Update: I would like to sort the journals by the newest post in them. Right now it sorts by the first post in journal. Any idea how to set this? (obviously setting the sort criteria on the sort field to ascending doesnt work, because it will just flip the list of journals...)

2

You have B that references A (single value entity reference field).

Construct your view as follows:

View of content (nodes) filtered by type A

Relationship: Entity Reference: Referencing entity (A bridge to the Content entity that is referencing Content via YOUR_ENTITY_REFERENCE_FIELD.). ISSUE - are you making this required? If you do then some A's that are not referenced will not show up. If you leave it as not required then unreferenced nodes will show up in the list either first or last, depending on whether sort is ASC or DESC.

Sort Criteria: Content: Post date, and set the relationship to the relationship added.

And that is it. To test your view you might want to add the field: Post Date, and set the relationship to the relationship added. This will show the post date of the referencing node so you can easily see if it works or not.

You might also want to add a second sort criteria.

  • Thanks for the reply Reynolds, This is exatly what I was trying, - except that Im using Node reference due to the fact that Im using Node reference count with reference views-. And I get no results in the field... in using Relationship: Content: Journal and Sort: (field_journal_reference) Content: Post date (desc) Any idea what am I doing wrong? – ventura Dec 19 '14 at 12:38
  • I got it, I had to use the reverse relationship field! Im marking your answer right because essentially its the rigth answer! Thanks. Btw any light on what this reverse relationship is and comes from? – ventura Dec 20 '14 at 14:25
  • @j-reynolds Do you have any thoughts on the update? – ventura Dec 22 '14 at 11:52
  • @dajka It sounds like you need to switch on aggregation in views, then add a sort field of date with proper relationship and aggregate MAX on it. Something like that. – J. Reynolds Dec 22 '14 at 13:37
  • Thank you! That helped! I got till the aggregation part, but couldnt figure out what max meant ;) now its clear and done! thank you again! – ventura Dec 22 '14 at 15:10

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.