Order ACF Relationship by Post Term Meta

Wow, that’s a fascinating puzzle you’re trying to solve! You might want to check out this thread for a partial answer. In that case, the data by which they wanted to sort the loop was located in the post itself, so I thought the solution would be to pass the post IDs directly to a post loop and then use the post loop’s query parameters to do the sorting.

Your situation is more complicated because the data is two levels deep (for each item in the relationship field loop, you want to dig into the post and then dig further into the taxonomy term applied to it). As far as I can tell, the current implementation of the sorting features in L&L allows you to sort based on a field value, but it doesn’t allow you to sort based on a set of instructions, which is what you’d need to achieve this kind of thing.

I’ve been thinking about this all weekend and here’s what I’m currently thinking. You could create a taxonomy term loop sorted by your custom field and then within that, display a post loop of all the posts within your relationship field that have the current taxonomy term applied. I don’t have a test site with a data structure that would allow me to test something like this so I’ve written this blind, but I’ve come up with the template below to express what I’m thinking. Let me know if it works or if I missed something.

<Set relationship_array><Field project_outputs /></Set>

<Loop type=taxonomy taxonomy=information_type orderby_field_number=info_type_priority>
  <If loop exists type=post id="{Get relationship_array}" taxonomy=information_type terms="{Field name}">
    <Field title /> <!-- This displays the term title but you could also display the current priority number -->
    <Loop>
      <Field title /> <!-- This is displays the titles of all the posts within that term -->
    </Loop>
  </If>
</Loop>

There may be a better way of achieving this, but that’s what I could come up with. Let me know if that makes sense. I’d be curious to know if anyone can come up with anything better!