# I can't orderings by array

**URL:** <https://community.prismic.io/t/i-cant-orderings-by-array/14561>\
**Category:** Developing with Prismic\
**Tags:** gatsby, rest-api\
**Created:** [November 22, 2023, 12:55pm UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561 "2023-11-22T12:55:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![winth](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@winth](https://community.prismic.io/u/winth)\
**Post date:** [November 22, 2023, 12:55pm UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/1 "2023-11-22T12:55:36Z")

</div>

![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/f/fdb0c571497ebc4e90ebbae71ea78b2828f055dd.png)  
I using Gatsby and prismic-javascript.  
I want to order by 2 values. But it doesn't work correctly

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 23, 2023, 11:53am UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/3 "2023-11-23T11:53:53Z")

</div>

Hi @winth ,

Welcome to the community!

So, the first thing I noticed is that you're ordering by `blog.data.order_number`

If you check our documentation...

> **[Document API Technical Reference](https://prismic.io/docs/rest-api-technical-reference#orderings)**
>
> The Prismic Document API is an extremely fast, flexible, and powerful engine for your content. This page provides definitions for all of the API parameters.

You'll see that the syntax is `my.[custom-type].[field]`.

So, in your case, it should be `my.blog.order_number`. Test this and let me know how you get on.

Thanks.

---

<div class="post-metadata">

**Author:** ![winth](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@winth](https://community.prismic.io/u/winth)\
**Post date:** [November 24, 2023, 3:13am UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/4 "2023-11-24T03:13:30Z")

</div>

Hi @Phil ,  
Thanks for your support.  
I use my.blog.order\_number, but it is still incorrect.  
For example:

- 1st priority: order number. For example, a post with order number 1st is displayed in the 1st position
- 1st publication: the post with the `order number` field blank will be sorted by 1st publication date.

I can't order by 2 values.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/e/ea143648b38ae46ee5b4408fe3ac1336ef7b484b.png)

---

<div class="post-metadata">

**Author:** ![winth](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@winth](https://community.prismic.io/u/winth)\
**Post date:** [November 24, 2023, 3:22am UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/5 "2023-11-24T03:22:47Z")

</div>

Hi @Phil,  
and another question, it throws an error when I use `my.blog.order_number asc`, if I don't have `asc` it is response incorrectly

FYI: prismic-javascript package version: 3.0.2

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/0/036efabf64f1a737378ec7b61334dbb5218e5c34.png)

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/b/bc6734f1bfeda04739811722e3e4f78cacb2980b.png)

---

<div class="post-metadata">

**Author:** ![winth](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@winth](https://community.prismic.io/u/winth)\
**Post date:** [November 27, 2023, 10:00am UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/6 "2023-11-27T10:00:50Z")

</div>

Hi @Phil,  
Can you help me resolve my problem?

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [November 28, 2023, 12:22am UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/7 "2023-11-28T00:22:59Z")

</div>

I'm wondering...  
I know the docs say that orderings can be an array, but I've always had luck with using an object. Here's my example:

```auto
/*
* The code below grabs products of a specific brand based on the slug (uid)
* and sorts them by ascending by their title 
*/
if (page.type === 'brand') {
    const products = await client.getAllByType('product', {
      graphQuery: `
        {
          product {
            brand
            title
            featured_image
            excerpt
          }
        }
      `,
      filters: [prismic.filter.at('my.product.brand', page.id)], 
      orderings: {
        field: 'my.product.title',
        direction: 'asc',
      },
    })

```

Hope that helps some.

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 30, 2023, 2:33pm UTC](https://community.prismic.io/t/i-cant-orderings-by-array/14561/8 "2023-11-30T14:33:50Z")

</div>

With Gatsby, you can sort your results in a different way, which might work better for you here:

> <https://github.com/prismicio/prismic-gatsby/blob/c8e7bbaec5fe4714227d23b0815aabdcec5b2d8d/docs/03-fetch-data.md#sort-results>
