Best approach for fetching "next story"?

Hello there,

I’m working on a project for a client where on certain pages we want to display the next page based on position in admin or alphabetically.

Imagine it like this: we have a page with a list of authors. If you click on an author, you go to the author detail page. On the bottom of that author detail page, we want to link to the next author (alphabetically).

So, in the detail page we want to fetch the story based on the author slug, then the next alphabetical order story after that slug. There seems to be no way of doing that, unless I’m missing something

I’ve tried multiple combinations of filter_query and other filtering methods, but none seem to be able to give me a decisive, expected result.

first_published_at_lt doesn’t work because we might have the case that multiple authors have been published for the first time all at once, resulting in the order not working.

I’ve tried filter_query with the position property, but since that field is outside of the content field it doesn’t work.

It feels really overkill to fetch all the authors in every author detail page just to find the next author.

Does anyone know of a good way to go about this without having to manually input “next author” in every authors content story in storyblok?

Hello @Folkert-Jan,

have you taken a look at using sort_by=position:desc or ...=position:asc? You can also sort by a field inside of the content type like the author name and then use simply the per_page parameter and the page parameter to define what author story from the sorted list you want to get next. You can find more information on the sort_by parameter on this Storyblok API Documentation page.

Best regards