Skip to main content
12 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 ...
Ben Croker's user avatar
  • 7,536
5 votes

Ordering entries based on an eager-loaded element's custom field

This requires a bit of extra work on the ElementQuery, but it can be done in the same query. We need to perform an inner join on the relation between the movie and the show and then another inner ...
Ben Croker's user avatar
  • 7,536
5 votes

Order/sort a structure section by date too?

This should work {% set entries = craft.entries({ section: 'news', sortOrder: 'postDate desc, lft asc', }) %}
carlcs's user avatar
  • 36.3k
5 votes
Accepted

How to order Sites

I've seen that before, if you look at the sites table in your DB, you'll see that a few sites might have their sortOrder set to 1. If you go to Settings → Sites → [the offending group] in your ...
Oli's user avatar
  • 7,495
4 votes

Order entries based on date field in the Control Panel

The CpSortableCustomColumns plugin lets you sort your element index tables on custom fields. Sounds like it does exactly what you want.
Marion Newlevant's user avatar
4 votes

Order entries by a category field alphabetically then paginate

In order to sort your entries by a related field you need to join the relations and the content table and sort your entries by the column you want. The it doesn't change the behavior of your paginate ...
Robin Schambach's 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 ...
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

Yearly/Monthy archive listing sorted by month

Add the reverse filter to your inner array of entries in month. http://twig.sensiolabs.org/doc/filters/reverse.html
carlcs's user avatar
  • 36.3k
3 votes
Accepted

How can I order a sections entries by their children entry postDate?

This should do what you want. {% set videos = craft.entries({ section: 'articles', type: 'video', level: 2, }) %} {% set articleIds = [] %} {% for video in videos %} {% set article = ...
carlcs's user avatar
  • 36.3k
3 votes
Accepted

How can I do nested ordering?

This should get you the desired results: {% for entry in craft.entries.section('yoursection').order('startDate desc, featured desc') %} {# Entry Code #} {% endfor %} If for any reason that ...
Christopher Healey's user avatar
3 votes
Accepted

Sorting across blocks (to get prev/next links)

You can get all of the works entries related to your contents Matrix field like so: {% set works = craft.entries({ relatedTo: { sourceElement: issue, field: 'contents.works' } }) %} They will ...
Brandon Kelly's user avatar
3 votes

Sort matrix blocks by date and limit to 10 entries

Your entry.agendav2 is not an array of elements but a ElementCriteriaModel so you can include both properties in your query {% for block in entry.agendav2.limit(10).order('Datum') %} That's ...
Robin Schambach's user avatar
3 votes
Accepted

Order entries by custom date and time fields

You'll want to change that startTime to field_startTime. Anything in the orderBy gets passed directly onto SQL and Craft is smart enough to do the replacement for startDate behind the scenes, but ...
Brad Bell's user avatar
  • 67.5k
3 votes

Ignoring "The " and "A " when sorting entries

How to achieve the same functionality on Craft 3? This is a MySQL specific answer (Craft 3 supports PostgreSQL as well), but you probably just need to escape your column names like so and that should ...
Brad Bell's user avatar
  • 67.5k
3 votes

orderBy title, but remove the word "The" from titles

{% set entries = craft.entries().section('media').orderBy("(CASE WHEN `title` LIKE 'The %' THEN SUBSTRING(`title`, 5) WHEN `title` LIKE 'A %' THEN SUBSTRING(`title`, 3) ELSE `title` END) asc"...
MarkD's user avatar
  • 85
2 votes

Hide users without profile pics

There's no photo attribute on the UserElementType, so you can't query by it like you're trying. Completely untested, but you can probably work around that with something like this: {% if ...
Brad Bell's user avatar
  • 67.5k
2 votes

Order tags by count - e.g. Top 10 Tags Used

Have had success using this plugin: https://github.com/philbirnie/CraftPopularTags
PhilR's user avatar
  • 418
2 votes

Order tags by count - e.g. Top 10 Tags Used

I couldn't quite get Carls answer to work (the "weightedTags"-array wasn't properly sorted), so I went and wrote a quick variable and service for achieving what I was after. First off, the super-...
Fuglsetrampen's user avatar
2 votes

Order entries, exclude 'the' from order criteria

Completely untested, but try something like this: {% for entry in craft.entries.section('hotels').order('(CASE WHEN title LIKE 'The %' THEN SUBSTRING(title, 4) ELSE title END )') %} MySQL's LTRIM ...
Brad Bell's user avatar
  • 67.5k
2 votes
Accepted

Ordering/sorting products by their variant stock level

Not possible at the moment, Craft would need to add better support for custom element sorting. Can you please submit the request here so we can track it: https://github.com/craftcms/commerce/issues ...
Luke Holder's user avatar
  • 6,837
2 votes
Accepted

Sort products by category field value

This doesn't work out of the box with Craft as the category field is a relation field. However you should be able to use SuperSort plugin. {% set products = craft.commerce.products.type('coins')....
pauliusef's user avatar
  • 163
2 votes
Accepted

Disable ordering

I think you can try .fixedOrder(), but you might have to query by ID and not slug. .fixedOrder(true)
AbbeyDesign's user avatar
  • 1,527
2 votes

How to get latest entries by particular field?

Looks like you're trying to echo out the results using {{ instead of actually setting it using %} tags. {% set entries = craft.entries.section('works').order('fieldname desc').limit(5) %} {% for ...
Alec Ritson's user avatar
  • 4,539
2 votes

Craft Commerce: Sort products by Sale price

What about this: {# Catch your products as you wish, here is just an example #} {% set categoryProducts = craft.products().relatedTo({ targetElement: currentCategory, field: 'productCategory' }...
RomanAvr's user avatar
  • 669
2 votes

Entries order postDate not working

positionedAfter only applies to entries within a structure section (https://craftcms.com/docs/templating/craft.entries#positionedAfter). See this answer for how to get next and previous entries.
darylknight's user avatar
  • 3,290
2 votes

Order a paginated entry by postDate

The code above is correct and working properly. There was a conflict with a masonry js file making the Craft ordering not work. Big thanks to @Anubarak for testing the code on their side.
Jon Livingston's user avatar
2 votes

Craft CMS - Dynamic Order Field Layout In Sections

Correct, there's no way out of the box to reorder fields on the fly in the Entry editor. If you're comfortable with Craft plugin development though I'm sure it's possible to extend Craft and add the ...
Jalen Davenport's user avatar
  • 3,045
2 votes
Accepted

Placing a Test Order (Craft Commerce)

If you are using the example templates, the dummy gateway should be enough to submit an order. Are you displaying any error flash message from the payment controller? <div class="flash">{{ ...
Luke Holder's user avatar
  • 6,837
2 votes
Accepted

Set OrderBy on Grouped Query Involving Smart Map Field

Okay, I've been able to solve this and figured I'd share what I discovered. The key for each group is the value of the state so really what I was after here was a key sort and just didn't realize it. ...
Tim Knight's user avatar
  • 1,022
2 votes
Accepted

How to create ordered list of categories from multiple category groups

You can query on multiple category groups like so: craft.categories.group('suitability, finish, shape, material, edge, surface').all() It can also be done with an array: craft.categories.group([ '...
Sam Hernandez's user avatar

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