Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPrev/getNext with criteria: custom fields not working #3019

Closed
pju- opened this issue Jun 22, 2018 · 2 comments
Closed

getPrev/getNext with criteria: custom fields not working #3019

pju- opened this issue Jun 22, 2018 · 2 comments

Comments

@pju-
Copy link

pju- commented Jun 22, 2018

Description

I try to create prev/next links for entries that are filtered by a custom field (a lightswitch field in this case).

The query is executed without respecting the custom field.

This seems to be due to a bug in the implementation of craft\base\Element -> _getRelativeElement.

In line 2158 when you do $query = clone $criteria; the behaviors of the object don't get cloned, so they get lost.

You can try this out by changing line 2169 from$elementIds = $query->ids(); to $elementIds = $criteria->ids(); which will produce the expected result (prev/next links are filtered by custom field), but that's not a generally valid solution of course.

Steps to reproduce

  1. I'm querying the field like this (with sectionTitle and customField replaced by actual existing values):
    {% set params = craft.entries.section('sectionTitle').customField(0).orderBy('title desc') %}
    {% set prevEntry = entry.getPrev(params) %}
  2. Instead of the prevEntry being populated with the entries filtered by customField, all entries from the section are taking into accord.

Additional info

  • Craft version: Craft Pro 3.0.12
  • PHP version: 7.1.11
  • Database driver & version: MySQL 5.5.5
  • Plugins & versions: irrelevant
@brandonkelly
Copy link
Member

(Related: #2857)

@pju-
Copy link
Author

pju- commented Jun 27, 2018

Awesome, thanks for fixing it so fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants