Query limit parameter issue

Yes, maybe… even if it sounds logical to limit the number of items returned by using the limit parameter. Actually, per_page means “give me n items per page” and limit means “give me only the first n items”, which is what I expected.

Just to clarify all this:

  • Pagination takes precedence over limit/offset: when pagination is active, the pagination page and per_page options are the only relevant limiting parameters.
  • In the REST API, pagination is turned on by default for list/browse endpoints. This is also generally the case on “browse” pages in the regular web interface. To get say, just 1 result from the REST API, setting per_page=1 is a perfectly fine, and the simplest, way to do it.
  • In the PHP API, there’s no limiting or pagination applied by default. If you pass only limit it will work fine; if you pass limit and page, page will take precedence as usual.
  • The “Browse Preview” block uses the PHP API when requesting the items to display in the block itself, so limit works here. But, the block has a separate box to put your desired limit value in; you must put your limit here and not in the query.
1 Like

Thanks John, I wish the whole documentation was as clear as your post :clap: