aelvan/Similar-Craft

Add a `limit` parameter to the query

joshuabaker opened this issue · 2 comments

Add a limit parameter to the query. Something like the below-pasted.

if (isset($data['limit'])) {
    $query->limit($data['limit']);
}

Other options would be helpful too (e.g. offset).

You can use both limit and offset (and any other parameters that are available to an ElementCriteriaModel) by creating an ElementCriteriaModel and passing it in as the criteria parameter, like so:

{% set limitCriteria = craft.entries.limit(4) %}
{% set similarEntriesByTags = craft.similar.find({ element: entry, context: entry.tags, criteria: limitCriteria }) %}

I understand now. Didn’t realise because it’s slightly different from the Craft paradigm. Thank you. 😁