Order Your Results

orderings

The orderings option orders the results by the specified field(s). You can specify as many fields as you want.

It will automatically order the field from lowest to greatest. Use "desc" next to the field name to instead order it from greatest to lowest. Both cases are shown below in the examples.

It is also possible to order documents by their first and last publication dates. The first publication date is the date that the document was originally published for the first time. The last publication date is the most recent date that the document has been published after editing. There is an example of each of these in the examples below.

Simply use the orderings parameter in your query options as shown below.

Examples

Copy
      //Order by price of product
{ orderings : '[my.product.price]' }

//Order by price of products from low to high and by title for products with the same price 
{ orderings : '[my.product.price desc, my.product.title]' }

//Order by first publication date
{ orderings : '[document.first_publication_date]' }

//Order by last publication date
{ orderings : '[document.last_publication_date]' }
    
Copy
      //Order by price of product
[ 'orderings' => '[my.product.price]' ]

//Order by price of products from low to high and by title for products with the same price 
[ 'orderings' => '[my.product.price desc, my.product.title]' ]

//Order by first publication date
[ 'orderings' => '[document.first_publication_date]' ]

//Order by last publication date
[ 'orderings' => '[document.last_publication_date]' ]
    
Copy
      # Order by price of product
{ "orderings" => "[my.product.price]" }

# Order by price of products from low to high and by title for products with the same price 
{ "orderings" => "[my.product.price desc, my.product.title]" }

# Order by first publication date
{ "orderings" => "[document.first_publication_date]" }

# Order by last publication date
{ "orderings' => "[document.last_publication_date]" }
    

after

The after option can be used along with the orderings option. It will remove all the documents except for those after the specified document in the list.

To clarify, let’s say you have a query that return the following documents in this order:

V9Zt3icAAAl8Uzob (Page 1)
PqZtvCcAALuRUzmO (Page 2)
VkRmhykAAFA6PoBj (Page 3)
V4Fs8rDbAAH9Pfow (Page 4)
G8ZtxQhAALuSix6R (Page 5)
Ww9yuAvdAhl87wh6 (Page 6)

If you add the after option and specify page 3, “VkRmhykAAFA6PoBj”, your query will return the following:

V4Fs8rDbAAH9Pfow (Page 4)
G8ZtxQhAALuSix6R (Page 5)
Ww9yuAvdAhl87wh6 (Page 6)

By reversing the orderings in your query, you can use this same method to retrieve all the documents before the specified document.

This option is useful when creating a navigation for a blog.

Sinply use the after parameter in your query options as shown below.

Copy
      { after : 'VkRmhykAAFA6PoBj' }
    
Copy
      [ 'after' => 'VkRmhykAAFA6PoBj' ]
    
Copy
      { "after" => "VkRmhykAAFA6PoBj" }