Member-only story
Use Reference Fields to Manually Order Content With Contentful and Gatsby
Order entries the easy way
I’ve recently started experimenting with Contentful as a headless CMS for a Gatsby based website. So far I’m impressed with how powerful the combination is. One of the requirements I was trying to figure out was the ability to manually reorder entries, as the order might need to be updated at any time.
Manual Ordering the Dirty Way
Initially, I opted to use an integer
field within the content model to help with manual ordering. At the time, this is the only way I could think of to make this work. After editing each entry to be in ascending order as I wanted, I was then able to sort by this field in the GraphQL query:
As you can probably imagine, to reorder the entries I needed to update them one by one to ensure the order field was correct. I wanted to keep exploring what Contentful had to offer.