Sort posts by newest child while keeping hierarchy intact

How do you retrieve and echo this structure in first place?

I don’t think you can query by something like this (without some wicked SQL), so it would be probably easier to:

  1. Retrieve parent posts.
  2. Look up newest child (query, sort by date, limit to one).
  3. Reorder parent posts accordingly.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)