29
votes
Accepted
Is it possible to exclude multiple sections from an entry search query?
The trick is to add and once before the first not
{% set entries = craft.entries.search(query).section('and, not this, not that') %}
16
votes
Accepted
How would I include the first category slug in the section's entry URL format?
This got it working for me:
/section/{categoryFieldName.first.slug}/{slug}
15
votes
Accepted
How to paginate search results?
{{ paginate.nextUrl }}?q={{ query }} did the trick with this setup.
15
votes
Accepted
Advanced query/filter based on date and values
You're actually closer than you might think. All you need to do is add your field handles as parameters. I prefer to use the hash style of declaring parameters but either way will work, I just find ...
13
votes
Accepted
Search matrix for blocks with upcoming dates
Here’s how you would do that:
{% set futureEvents = entry.myMatrixField.myDateField('>= '~now) %}
{% for event in futureEvents %}
{{ event.description }}
{% endfor %}
Update:
This actually ...
12
votes
Filter Entries by Field Value
Filtering a list of entries is quite simple. Here's an example from one of our sites:
{% for job in craft.entries({
section: 'jobs',
applicationsClose: ">= " ~ (now|date('Y-m-d')),
...
11
votes
How can I display search "excerpts" from multiple sections?
There is no way at present to delegate a field as the search excerpt field in Craft, so it needs to be handled by the search results template. It is possible to use conditionals but this can bloat the ...
11
votes
Accepted
Display entries if Field Date is past Now
You can combine a for and if statement in twig, so you don't necessarily need to use search.
Something like this might get you a bit closer:
{% for entry in craft.entries.section('event') if entry....
11
votes
Accepted
Select entries starting with same letter from alphabet list
First, you should create a dynamic route (something like "games/glossary/<slug>") and point it to a template. A dynamic route means you won't have to create a template for every letter. Note the ...
10
votes
Accepted
Search order "Score" criteria
When Craft is determining a matching element’s score, it will loop through each of the search terms, and for each one, loop through each of the element’s attributes, and add the following points to ...
10
votes
Accepted
Using “search” vs. “relatedTo” in a template
To be honest, those two parameters may seem to be slightly similar but provide a totally different functionality.
From their documentation on search:
search
Only fetch entries that match a given ...
10
votes
Accepted
Building Results From Advanced Search Form
You can set multiple conditions on a single ElementCriteriaModel parameter. Pass it either a comma-separated list as a string or an array of conditions.
{% set entries = craft.entries.id('84, 62, <...
10
votes
Accepted
How to filter entries by clicking multiple categories on front end
First, I would use something like training in your query string. It's a little more readable and you aren't searching for the words lunge and dumbbell anywhere in those entries, just entries related ...
9
votes
Accepted
How can I display search "excerpts" from multiple sections?
This can be accomplished using a conditional:
{% if entry.section == 'sectionA' %}
{{ entry.sectionAField }}
{% elseif entry.section == 'sectionB' %}
{{ entry.sectionBField }}
{% endif %}
or ...
9
votes
What is the best way to track, record or view search terms?
We track search terms on buildwithcraft.com the same way we track all other site activity: using Google Analytics.
All you have to do is throw GA event tracking code into your search results template....
9
votes
Accepted
Filter based Search Form
I managed to figure this out by looking through a few other posts:
Advanced Search
Building a simple search by multiple categories
Building Results From Advanced Search Form
How to filter entries by ...
9
votes
Accepted
How to fetch entries in custom plugin Craft 3?
For instance like this:
$entries = Entry::find()
->section('sectionName')
->orderBy('fieldName')
->limit(null)
->all();
Have a look here in the documentation (for the ...
8
votes
Accepted
Building a simple search by multiple categories
Building the form is pretty straightforward, you get the categories from your "locations" and "types" category groups using craft.categories
and loop them to build your select options. I choose to ...
8
votes
Accepted
Searching a specific section by four different types of parameters?
One method is to build your params before performing the search.
{# set base params #}
{% set params = {
section: 'portfolio',
limit: null
} %}
{% set relatedParams = ['and'] %}
{# status #}
...
8
votes
Accepted
How do I exclude a Channel, Structure or Singles from search?
This should work for a single section:
{% set entries = craft.entries.section('not news').search(query).order('score') %}
to exclude more sections:
{% set entries = craft.entries.section([
'and'...
8
votes
Accepted
Filter Entries by Field Value
Use the search parameter in the craft.entries model:
{% for entry in craft.entries.section('Blog').search('featuredFieldName:1') %}
{# Entry Code #}
{% endfor %}
To filter by a specific text ...
8
votes
Accepted
Craft 3 Multi Category and Field Search
Solved this by merging the search parameters together for both the multiple categories and the number fields if they were set in the url parameters. This solves the loop.last pagination problem as ...
7
votes
Accepted
How would you recommend integrating craft with Algolia
Disclaimer : I'm the dev of the SearchPlus plugin
The SearchPlus plugin by SquareBit (currently in private beta) integrates directly with Algolia and handles all the index population and updates.
...
6
votes
Accepted
Bug with non-ascii characters, quotes and OR operator in search?
This looks like a bug to me too. Here are the search terms and generated queries:
'pølser OR pålegg' -
SELECT * FROM `craft_searchindex` WHERE (MATCH(`keywords`) AGAINST('pølser palegg' IN BOOLEAN ...
6
votes
Accepted
How to search by title field only?
This seems to work:
{% set entries = craft.entries.section('not lakeDetails').search('title:' ~ query).order('score') %}
6
votes
Accepted
Paginate an array with multiple filters
Try using this (completely untested):
{% if paginate.prevUrl %}
<a href="{{ paginate.prevUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Previous Page</a>
{% endif %}
{% if ...
6
votes
Accepted
Search Results In a Drop List/Popup on Same Page
You can request any template via ajax using jQuery. jQuery would essentially listen for onChange events from the search field and ajax load a template that looped through the search results.
The ...
6
votes
Accepted
How do I get extracts in search results?
I think creating your own Twig filter is your best bet.
So, create a filter that takes a string, searches that for another string and returns an extract. It could do this by using some regular ...
6
votes
multiple search
Your search syntax of craft.entries.section('pages').search('foo:bar foo2:bar2') should work and is the equivalent of saying "give me all of the entries in the pages section where the field foo is ...
6
votes
Filter Entries by Field Value
{% set featuredProducts = craft.entries
.section('sectionName')
.featured(true)
.all() %}
Where sectionName is the name of your section;
featured is your featured field handle;
true is ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
search × 318entries × 43
craft3 × 35
filter × 28
templating × 22
categories × 21
matrix × 19
relations × 18
query × 13
plugin-development × 12
assets × 12
control-panel × 12
field × 11
users × 10
elementcriteriamodel × 10
tags × 8
plugin-craftcommerce × 7
entry × 7
pagination × 7
params × 7
sections × 6
category × 6
checkboxes × 6
datetime × 5
relatedto × 5