1

I'm new to craft so may it be a basic question, however I can't find an answer for it :-/

I have custom field 'width' in my entry type defined as integer. What I need to achieve is quite simple:

{% set entries = craft.entries.section('windows').find({'width':'> 0'}).order(width) %}

The important now is the .order part it's not working right now :-(. What is correct way to do this? I have found some plugins but I believe craft can do this somehow… It always does (so far).

Thanks for any info on this.

2 Answers 2

3

Craft 2

Either of these should work (they are equivalent):

{% set entries = craft.entries.width('> 0').section('windows').order('width') %}

or

{% set entries = craft.entries({
  section: 'windows',
  order: 'width',
  width: '> 0'
}) %}

The reason you are getting "Array to string conversion" error is that find has turned your ElementCriteriaModel into an array.

Craft 3

order is now orderBy

Craft 3 Docs: Element Queries

1
  • Yes! Thanks, this really works as it's supposed to, no plugins needed.
    – klaxon
    Commented Apr 18, 2016 at 8:48
2

Have you tried putting in 'width' instead of width?

The order parameter expects a string, not an object, as it just needs to know the name of the field name to filter by.

Final code would look like:

{% set entries = craft.entries.section('windows').find({'width':'> 0'}).order('width') %}
1
  • Yes, but that ends with „Array to string conversion“ error.Thanks anyway. In the craft's docs there is written that only textual fields can be used to order. Wierd. So I have superSort plugin installed… and I can order by width field. But still believe that craft should do this naturaly. It does with assets.
    – klaxon
    Commented Apr 14, 2016 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.