nystudio107 / craft-similar

Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.
https://nystudio107.com/
MIT License
26 stars 5 forks source link

Limit filter stopped working?! #48

Closed DavidKabelitz closed 4 months ago

DavidKabelitz commented 1 year ago

Describe the bug

Something we recognized at all our projects the limits are not working. I am not sure when it stopped working but instead of just displaying 6 entries the code below shows all entries that were found.

Does something changed we need to adjust? Code worked fine for a very long time.

Regards!

Code example we usually work with:

` {% set timeAgo = now|date_modify('-1 month') %}

{% set postDateParam = '> ' ~ timeAgo|date('U') %}

{% set ids = entry.contentTags.ids() | merge(entry.categoryLatest.ids()) %}

{% set limitCriteria = craft.entries.section(['aktuelles']).with(['video','imageLatest','categoryLatest','title','postDate','caption']).postDate(postDateParam).limit(6) %}

{% set similarEntriesByTagsAndCategories = craft.similar.find({ element: entry, context: ids, criteria: limitCriteria }) %}`

Versions

khalwat commented 1 year ago

The last update to the plugin was just under a year ago; so I'm not aware of anything changed on this end that could be causing the issue?

Mosnar commented 1 year ago

I can confirm this is an issue on my end as well. Something must have changed in Craft.

khalwat commented 1 year ago

@Mosnar lmk if you come up with any details!

DavidKabelitz commented 1 year ago

@Mosnar to still use it we set a limit at the for loop on top, limit at the criteria does not work anymore. Our quick fix solution... {% for item in similarEntriesByTagsAndCategories[:column.limit] %}

Mosnar commented 1 year ago

@DavidKabelitz Thanks! I'm digging into the source of the problem. I can see that it emerged after updating from 3.7.55.3 to 3.8.5, so that narrows it down a bit.

Mosnar commented 1 year ago

@khalwat I found the culprit - this change is nullifying the limit from the criteria: https://github.com/craftcms/cms/commit/c6666293d0be56668389a2cc558a773d9a409e39

Here: https://github.com/nystudio107/craft-similar/blob/aa657974e72957f98e1de4eced0f64fe2a835066/src/services/Similar.php#L78

Mosnar commented 1 year ago

Sorry for the blast of comments! Turns out this is due to a field within a matrix block with the handle limit. After renaming all of those field handles, everything seems to be working as expected. This makes sense in the context of Brandon's aforementioned change.

khalwat commented 1 year ago

So... should I close this up?

khalwat commented 4 months ago

@DavidKabelitz I closed this issue due to @Mosnar 's comments, but if the issue persists, we can continue looking to address it.