Collection : multiple contains condition and word with accent #6937
Unanswered
mediactive
asked this question in
Q&A
Replies: 1 comment
-
The You can't do multiple like you've noticed but you could whip up a quick custom scope to handle it. https://statamic.dev/extending/query-scopes-and-filters#scopes <?php
namespace App\Scopes;
use Statamic\Query\Scopes\Scope;
class Keywords extends Scope
{
public function apply($query, $values)
{
$keywords = explode('|', $values['keywords']);
$query->where(function ($query) use ($keywords) {
foreach ($keywords as $keyword) {
$query
->orWhere('title', 'like', '%'.$keyword.'%')
->orWhere('description', 'like', '%'.$keyword.'%');
}
});
}
} {{ collection:articles filter="keywords" keywords="{keyword1}|{keyword2}" }} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I would like to allow keywords search in 2 fields of a collection (title and description).
I use this code:
{{ collection:public_notices sort="start_at:desc" description:contains="{ $keyword1 }" title:contains="{ $keyword1 }" description:contains="{ $keyword2 }" title:contains="{ $keyword2 }" }}
It doesn't work.
This code, with a single "contains" condition works:
{{ collection:public_notices sort="start_at:desc" description:contains="{ $keyword1 }" }}
How to allow the search with several keywords and display results containing at least 1 of the keywords used for the search.
How to do the "contains" condition work with accented words, like "québec"?
Thanks a lot for your help!
Beta Was this translation helpful? Give feedback.
All reactions