johnstephens Posted October 16, 2020 Posted October 16, 2020 I have a list of articles that I want to sort alphabetically by the author's lastname. The author(s) are linked to each article's page using a page reference field, and the author pages have a field for their lastname. Most articles have only one linked author page, but some may have more than one. For sorting, I only want to consider the first author in the list. I'm stumped how to make this work. $articles = page()->children('sort=FIRSTAUTHOR'); // ?? If I get one page from the list, I would be able to select the field I want to sort by like so: foreach ($articles as $article) { $sortfield = $article->authors->first()->lastname; } Thanks in advance for any guidance you can offer!
johnstephens Posted October 16, 2020 Author Posted October 16, 2020 This feels like a case for sub-selectors, but I'm not sure how to put it together.
johnstephens Posted October 16, 2020 Author Posted October 16, 2020 I figured it out! Sub-selectors was the wrong approach, but a subfield selector seems to do the trick: $articles = page()->children('sort=authors.lastname'); Woo. Love it! 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now