Skip to main content
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')), ...
Simon East's user avatar
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....
Steve Holland's user avatar
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 ...
Mats Mikkel Rummelhoff's user avatar
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 ...
KSP's user avatar
  • 849
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 ...
kmgdev's user avatar
  • 1,199
8 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 ...
DimaS's user avatar
  • 181
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 ...
Chattervast's user avatar
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. ...
RitterKnight's user avatar
  • 6,582
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 ...
Lindsey D's user avatar
  • 24k
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 ...
Jeremy Daalder's user avatar
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 ...
carlcs's user avatar
  • 36.3k
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 ...
carlcs's user avatar
  • 36.3k
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')....
Brandon Kelly's user avatar
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 ...
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Search everywhere

Sure, just remove the section parameter altogether. {% set entries = craft.entries.search(query).order('score') %}
carlcs's user avatar
  • 36.3k
4 votes
Accepted

Searching for any keyword in query

One way to do it is to split the search query on spaces, and then join it with 'OR': {% set query = craft.request.getParam('q')|split(' ')|join(' OR ') %} {% set entries = craft.entries.search(query)....
Mats Mikkel Rummelhoff's user avatar
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 | ...
Trevor Davis's user avatar
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, ...
dmatthams's user avatar
  • 2,492
3 votes

Booking system based on Charge 2.0

Developer of Charge here. Yes - Charge supports all the native Craft criteria search parameters for fields. Like you mentioned, there are a few special fields that aren't supported currently within ...
Joel Bradbury's user avatar
3 votes

Automatically link to entries in rich text field

How about just using the replace filter? {% set text = "A small boat surrounds a large ​island​​" %} {% set linkedText = text|replace({'boat':'<a href="/whatever">boat</a>'}) %} {{ ...
Jeremy Daalder's user avatar
3 votes
Accepted

Search using the MX Range Slider plugin

The way the plugin is currently written, it won't support your initial syntax. i.e. range('and', '>=' ~ result.points, '<=' ~ result.points). It would need to override BaseFieldType's ...
Brad Bell's user avatar
  • 67.5k
3 votes

Display entries if Field Date is past Now

Craft has changed since the above answer was given. The now object must be a part of the string, rather than concatenated as an object. so instead of: {% set futureEntries = craft.entries.section('...
ToddPadwick's user avatar
3 votes

Fetching entries from an advanced search form on the front end

I came across a similar issue today where I was creating a search form that included checkboxes. I did it as follows. First, I checked if the URL had the query string I was looking for and joined the ...
JxM's user avatar
  • 141
3 votes

Filter Entries by Field Value

Another way for Craft 3 {# Create an entry query with the 'section' and 'limit' parameters #} {% set entryQuery = craft.entries() .section('Blog') .search('entryColor:green') .limit(10) %} ...
Damon's user avatar
  • 4,706
3 votes
Accepted

Using the Search Filter with Entry Fields

{% set range = entry.model %} {% set categories = craft.categories.slug('not preferential') %} {% set entries = craft.entries.section('offers').search('title:' ~ range).relatedTo(categories) %} If ...
mcclaskiem's user avatar
3 votes

Tag mysteriously not found

You don't need to use the search parameter in this case. I'd avoid using it where ever possible. {% set tag = craft.tags.slug(slug).first() %}
carlcs's user avatar
  • 36.3k
3 votes

Check if Category is in Query

In Craft 3 you don't have to iterate through the chidlCategories manually, you could use the column filter instead, like this: {% set queryCatSlugs = childCategories.all() | column('slug') %} {% if ...
Ottó Radics's user avatar
3 votes

How do I get extracts in search results?

I know this is an old question but i stumbled upon it while searching for an answer so others might find it as well and I wanted to share my solution which is not perfect but works really good for all ...
Josh's user avatar
  • 31
3 votes
Accepted

Order by fields after searching

Not really feasible without a plugin – fortunately, there's the excellent SuperSort: {% set results = craft.entries.section('player').search('team:"thenameoftheteam"') %} {% set ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Is there a way to reduce the search index?

Craft 3: In Craft 3, a plugin can listen to the Element::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES event to modify the searchable attribute list of an element before it is indexed. Craft 2: Currently ...
Brad Bell's user avatar
  • 67.5k

Only top scored, non community-wiki answers of a minimum length are eligible