sorting a loop by two keys
-
I have a catalogue of books on my site. To each book can be assigned one, two or three literary awards (for example Nobel Prize, Man Booker Prize, etc.). They are stored in custom fields. I want to display related books by a prize and sort them by a year of prize. The problem is that sometimes the prize will be in the first custom field (prize_1), sometimes in the second custom field (prize_2). It goes the same with the years (year_1, year_2).
Is it possible to sort a loop by two keys (years of prizes) at the same time? I use something like that (it shows every book with the prize, no matter which custom field is used), but I can only use random sorting…
In short: I have two loops, but I want to sort them together.[if field=”prize_1″]
[pass field=”prize_1″]
[loop taxonomy=”category” term=”books” field=”prize_1″ value=”{FIELD}” exclude=”this” orderby=”field_num” key=”year_1″ order=”desc”]
[field title-link] ([field year_1])
[-if empty]Brak.[/-if]
[/loop]
[loop taxonomy=”category” term=”books” field=”prize_2″ value=”{FIELD}” exclude=”this” orderby=”field_num” key=”year_2″ order=”desc”]
[field title-link] ([field year_2)
[/loop]
[/pass]
[/if]Result:
title, 2014
title, 2013
title, 2012
title, 2009
title, 2011
title, 2010, etc.Preferred result:
title, 2014
title, 2013
title, 2012
title, 2011,
etc.
- The topic ‘sorting a loop by two keys’ is closed to new replies.