Hot answers tagged

9 votes
Accepted

How to order or filter entries by their author's custom field?

This requires a bit of extra work on the ElementQuery, but it can be efficiently done in the same query. We first perform an inner join on the author's content table using the authorId so that the ...
user avatar
  • 6,226
7 votes
Accepted

How to get the order number of the current entry in a structure

There's a positionedBefore parameter for craft.entries. Use this with a criteria model filtered to show the entries you are interested in only. {% set parent = entry.getParent() %} {% set siblingsIds ...
user avatar
  • 35.8k
6 votes
Accepted

group Matrix blocks and also order by Matrix field for a given block

This is a great chance to use the group filter. First, get all your matrix blocks as an array: {% set talkBlocks = entry.talks.find() %} Then group them by type: {% set talksByCategories = ...
user avatar
6 votes
Accepted

Set Entries field in Commerce order on completion

See What is getContent() / the ContentModel, and how do I use it to get and set custom field values? So you needed to change the method used for setting content on an element. Also see In a plugin, ...
user avatar
  • 6,682
5 votes
Accepted

Craft Commerce: Sort Products By Price

Close! This should do it: {% set products = craft.commerce.products({ relatedTo: (category), order: 'defaultPrice', }) %} With the quotes it's a string. Without the quotes, Twig is ...
user avatar
  • 66.4k
5 votes
Accepted

Order grouped entries

The probably most easy way to do this is to sort the grouped array by key, which unfortunatelly is only possible with a plugin, as Twig's sort filter only allows to sort by value. Here I'm using ...
user avatar
  • 35.8k
4 votes
Accepted

Order entries by custom time field

Craft always saves a complete DateTime value to the database, even if you only make it set / show the time part of it in the Control Panel. To ignore the date part (which in this case is set to the ...
user avatar
  • 35.8k
4 votes

Order entries based on last string of title

Another option is to use the Preparse plugin to automatically parse out and store last names in a hidden field. Install the Preparse plugin Create a new “Last Name” field using the Preparse field ...
user avatar
4 votes

How do I set the value of a custom entries order field from a plugin?

I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field. Since an entries field is an array of elements, not just a single element, I just needed to ...
user avatar
  • 373
4 votes
Accepted

Order PDF in back-end error with Globals

Since the templates are rendered on the server and not in a regular http request (in the front end templates), the globals are not loaded automatically, into the global twig namespace. You can still ...
user avatar
  • 6,682
4 votes
Accepted

Creating a sitemap/index page, ordered by A-Z and 0-9

The way to do this is with the group filter. You want to group the entries by the first character of the title. Get the entries as an actual array {% set allEntries = craft.entries.section('artists')...
user avatar
3 votes
Accepted

How to order matrix blocks in reverse

I went and looked at the MatrixBlockModel; there's an attribute named sortOrder (If you output {{sortOrder}} inside the for loop, it will display the index of that block). You can use that attribute ...
user avatar
  • 3,195
3 votes
Accepted

Decimals missing in result after adding up order totals for a customer

The trouble you are running into is trying to add a string value to an integer to get your total. You have to use order.totalPrice without the currency filter to be able to add all the values ...
user avatar
  • 3,833
3 votes
Accepted

Query two sections filtered by different custom fields, then order them

There's this super useful SuperSort plugin that would make this possible. {% set sortAsTemplate = '{{ object.section == "Exhibitions" ? object.startDate|date("U") : object.date|date("U") }}' %} {% ...
user avatar
  • 35.8k
3 votes

How to order by related entry type field

Try something slightly different in concept... On your Products template - /products/index.html - start with your Authors first and then look for the Products which are related to them. Hopefully ...
user avatar
  • 1,538
3 votes
Accepted

Order entries based on last string of title

It’s not possible to do that unless you’ve already got the last word saved somewhere. Here’s what I would recommend: Create two new Plain Text fields - “First Name” and “Last Name” Go to your People ...
user avatar
3 votes

ElementAPI: How to order and/or limit results?

Just setting the limit property doesn’t do the trick alone, you need to deactivate pagination, too: 'criteria' => [ 'section' => 'trucks', 'limit' => 10, 'orderBy' => '...
user avatar
3 votes

Sort entry titles alphabetically excluding 'The'?

According to SUBSTRING, the first character starts at 1. So if you wanted to start at the position immediate after The (with one space), you'd need to start at position 5. Just did a test locally ...
user avatar
  • 66.4k
3 votes

Option and notes fields after cart at checkout for order, not just line items

First, add a custom field to your orders, let's call it orderNotes. Then, in any updateCart form, you can use an input with name="fields[orderNotes]" to set the value of that field. (Line items ...
user avatar
2 votes
Accepted

Is it possible to order entries by Entry type title/slug

I don't think it's possible to order by the name or handle of Entry Types. To order by the ID of your Entry Types use 'typeId' as the value: {% set entries = craft.entries.section('more-info').order('...
user avatar
  • 35.8k
2 votes

How to order categories in key/value for loop?

Using the group filter you will always end up with the sort order of your entries. So you would need to sort the entries by your categories field, but this probably doesn't work. But you can do the ...
user avatar
  • 35.8k
2 votes
Accepted

Order Sprout Forms by field handle returns an error

This will now work as of Sprout Forms v2.2.0: {# Ordering #} {% for formEntry in craft.sproutForms.entries.formHandle('contact').order('address desc') %} ... {% endfor %} {# Filtering #} {% for ...
user avatar
  • 13.2k
2 votes

Order Sprout Forms by field handle returns an error

It seams, that the columns for the form values are not part of the sql, that's why it never will work like this. Maybe it works in upcomming versions of the Sprout Forms plugin. As a workaround you ...
user avatar
  • 1,317
2 votes
Accepted

Conditionally Applying CSS to Element on Active Page Without Using URL or ID Logic

The craft_structureelements table contains the data you need to determine the exact position & level of each entry in your structure. But you'd need some fancy plugin logic to attack that data and ...
user avatar
  • 23.6k
2 votes
Accepted

Sort single entries by section with same query order

This is only possible with the id parameter in combination with fixedOrder. {% set entries = craft.entries.id([307, 287, 488]).fixedOrder(true) %} You can look up your singles' IDs in the URL of ...
user avatar
  • 35.8k
2 votes
Accepted

Order Users List by Last Entry Date

I just noticed that you've posted an answer to your question already. Your approach using the group filter is probably all you need, as the allDesigns array is sorted by postDate desc and by using ...
user avatar
  • 35.8k
2 votes

Order grouped entries

Stumbled upon this looking to answer similar problem. You should be able to do this now without a plugin, using the multisort filter where you iterate through your profiles, e.g.: {% for profile in ...
user avatar
2 votes
Accepted

User Order History Not showing Up in CP

The Order History is the history of that particular order and not designed to pull in other prior orders from that customer. You might want to make a feature request if you want to be able to see ...
user avatar
2 votes
Accepted

ElementAPI: How to order and/or limit results?

This should do the trick: 'criteria' => [ 'section' => 'trucks', 'limit' => 10, 'order' => 'title asc', ] The Element Criteria Model documentation has more information ...
user avatar

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