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
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
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'...
10
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
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.
...
7
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 ...
6
votes
Need no search engine tracking option in Craft websites
If you're used to another CMS such as WordPress, you're probably used to using a Discourage search engines from indexing this site option. As Robin's answer mentions, the training wheels are off.
...
5
votes
Excluding fields in a search
You can now use the attribute parameter in your search options, to set the fields the search term should apply to (feature introduced with Craft 2.5).
Unfortunatelly it's currently only possible to ...
5
votes
Accepted
Filter entries by entry type in the CP?
What you can do is to create additional entry sources using the modifyEntrySources hook.
This is a very simple example, that will add a heading and two sources to the end of the
sources list (below ...
5
votes
Accepted
How to search using partial words?
That's because Craft doesn't do fuzzy searching by default. You'd need to use the wildcard 'Peru*' to match 'Peruvian'. You can see the full list of supported search syntaxes here: http://...
5
votes
Accepted
Entry not showing up in search results?
As Brad mentioned, you’re not getting any results because your search query requires both keywords to be present, but you don’t have any fields that have both keywords.
You can solve this with a ...
5
votes
Accepted
Ignore fields in search index
As of Craft 3, there is a RegisterElementSearchableAttributesEvent event that a plugin can listen to to change modify what gets saved to the search index table when an element is saved.
5
votes
Accepted
Search against a checkboxes field's options
Checkboxes / multiselect fields store to the database in a very query unfriendly way.
That's why I would really recommend to use categories, tags, lightswitches instead, if you intend to
query against ...
5
votes
Accepted
.relatedTo() not returning tags with spaces
In your working example, you’re mapping request.tags to the search param, but in the non-working example, you’re mapping it to the slug param.
Those two params are handled in very different ways. ...
5
votes
Accepted
Converting array of entries to an array of ids
Simply append .ids() to your initial query...
{% set authorIds = craft.users.search('fullName:*' ~ query ~ '*').ids() %}
Without the .ids() method, you're actually working with an Element Criteria ...
5
votes
Accepted
How do I export search results as a csv?
You can just make link to a twig template to output a csv quite simply...just like any other template really, except it won't extend you layout etc. and will simply contain something like:
{%for ...
5
votes
Accepted
Prettify search URL
You forgot to setup the routes for your search URLs.
In this case I’d recommend to use an advanced route with a regular expression, as it allows to use patterns that will ignore the slashes between ...
5
votes
Accepted
How to filter entries based on Tags
You can combine multiple relationship criteria by passing an array to the relatedTo parameter with the keyword 'and' or 'or' as the first array element. You want your entries to be related to any of ...
5
votes
Accepted
Advanced Search with tags and categories
Before I answer your main question, I'm seeing a couple issues with what you’re currently doing that are worth correcting.
First, this code:
{% set supplierCat = craft.categories.group('supplier')....
4
votes
Accepted
Method (plugin free?) to combine search results across multiple searches (and element types)
To get this working I submitted a patch to 'SortByField' - https://github.com/dannynimmo/craftcms-sortbyfield - to get this plugin to work with Commerce products - and I now do this:
{% set ...
4
votes
Accepted
Get entries by date range from plugin
Ok, found an answer that made it a bit clearer:
How do I get elements using getCriteria from a specific date?
Basically you can do this:
$criteria = craft()->elements->getCriteria(ElementType::...
4
votes
Accepted
Hide search results depending on field value
Instead of adding the filtering criteria to the search parameter, I would use a custom field parameter for the showInSearch field.
{% set miniCards = craft.entries.search(query).showInSearch('not 1')....
4
votes
Accepted
Get field that contains search query
This currently isn't possible natively in Craft, but if you think it should be, you can create a feature request!
4
votes
Accepted
Fuzzy Search and Plurals
With the current search implementation in Craft, if you have subLeft and subRight set to true for the defaultSearchTermOptions config setting and you search for "intaglios", what Craft does behind the ...
4
votes
Accepted
Search everywhere
Sure, just remove the section parameter altogether.
{% set entries = craft.entries.search(query).order('score') %}
4
votes
Grouping entries by title in Craft 3
Not exactly sure what you are trying to do with this data, but it sounds like you could use the group filter
{% set alphaEntries = craft.entries.section('shops').type('shops').all() | group('title | ...
4
votes
Accepted
Excluding specific field value from search
The light switch value should be taken out of the search query and put into the entry query:
{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set results = craft.entries({
section: querySections,
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
search × 329entries × 44
craft3 × 39
filter × 28
templating × 22
categories × 21
matrix × 19
relations × 18
query × 14
control-panel × 13
plugin-development × 12
assets × 12
field × 11
users × 10
elementcriteriamodel × 10
tags × 8
pagination × 7
params × 7
plugin-craftcommerce × 6
entry × 6
sections × 6
category × 6
checkboxes × 6
datetime × 5
relatedto × 5