Modifiers

Modifiers are things that you can add to your query that don't get matched against and instead affect the results you get back.  They can be dropped into a query anywhere.  The three worth knowing are:

  • count
  • orderBy
  • page

So to get the second page of your blog homepage, you would use all three of these together:

{'type':'post','parent':blog.id,'orderBy':'-publishedAt','count':10,'page':2}

This would return posts 11-20, ordered by newest first.

Count

Count limits the number of results you get back.   Here is a basic example of getting the five newest blog posts:

{'type':'post','orderBy':'-publishedAt','count':5}

It should be noted that count is currently limited to a maximum of 100. If left blank, 20 items will be returned.

NOTE: Currently all permissions checks are run AFTER the initial count filter.  This means it is possible that your results may contain a fewer number of items than expected. This is an issue that we're looking to correct.

orderBy

This is the most complicated modifier, but that isn't saying much. It simply allows you to choose which field you want to order your results by.  The most common use of this is to get items that were published the most recently:

{'type':'page','orderBy':'-publishedAt'}

OrderBy takes a field as a value.  If it has a '-' in front of it, it will order them in reverse.  It will order things either numerically or alphabetically depending on what type the field is.

Page

Page works in conjunction with count.  If you're not also using count, things won't work properly.  If you specify a count of 10 and a page of 2, you'll get back the results numbered 11-20.  Here is a typical example of grabbing the second page of a blog archive:

{'type':'post','parent':{'type':'feed','url':'/blog'},'orderBy':'-publishedAt','count':10,'page':2}

Currently there is no indicator that comes back that will tell you if there is an additional page after the current one.