10
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 ...
- 7,071
9
votes
Accepted
Order entries by category field
Here's a solution using the group filter.
{% set entriesGrouped = craft.entries.relatedTo(category).order('title')|group('myNewCategoriesField.first().title') %}
{% for group in entriesGrouped %}
...
- 36k
8
votes
How to order by matrix field?
My SuperSort plugin is built for use cases exactly such as this. It allows you to render each object in your array using a Twig object template and sort the array based on the rendered value.
- 3,400
5
votes
Accepted
Change field arrangement from the entries page
No, that's not possible with Craft at the moment (2.4). You'll have to use the Field Layout Designer from Settings -> Sections -> {Section} -> {Entry Type} to manage your fields and tabs.
You could ...
- 21.7k
5
votes
How to order numbers naturally?
I think the simplest solution is to use a plugin like Twig Better Sort or SuperSort. With those you would query for your entries as normal and then apply the Twig filter to sort the array.
{% set ...
- 36k
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 ...
- 7,340
4
votes
How Do I group entries by Category and retain fixed Category Order?
Depending on your needs, you may be able to ditch the group() filter and sort your list however you need.
Get all your entries and categories. Then use the relatedTo functions to filter those lists.
...
- 2,592
4
votes
Accepted
Reverse Assets fixedOrder
You could try twig's reverse filter.
{% for asset in entry.assetsField|reverse %}
<img src="{{ asset.url }}" alt="{{ asset.title }}"/>
{% endfor %}
- 13.4k
4
votes
Accepted
Output entries sorted by category title and paginate
Not exactly what you're looking for, but it gets you closer. This should display the order you want, but it doesn't have any pagination (and honestly I'm not sure if that's possible using Craft's {% ...
- 66.9k
4
votes
Accepted
Sort / Order Entries on select or button click
Okay so you can either do this through ajax or through a page reload, a page reload is going to be much easier, but you can get it to work without reloading the page...
Reloading the page
You can ...
- 4,519
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.
- 12k
4
votes
Order/sort a structure section by date too?
This should work
{% set entries = craft.entries({
section: 'news',
sortOrder: 'postDate desc, lft asc',
}) %}
- 36k
4
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 ...
- 7,071
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
...
- 19.6k
3
votes
Loop through entries with custom ordering, showing one from each category then start loop again
I'd suggest breaking your problem down into code which gathers the IDs of each of the types of entries first, then outputs them....roughly like this (very much untested!! - but should be enough to ...
- 7,557
3
votes
Accepted
Unable to sort large number of blocks in Matrix field in CP and template
This is because Craft stores the sortOrder values in the database with a MySQL column type of tinyint that happens to be signed, which means it can store a range of -128 to 127.
Aside from the fact ...
- 66.9k
3
votes
No ordinary news post ordering
My SuperSort plugin is built for use cases exactly such as this. It allows you to render each object in your array using a Twig object template and sort the array based on the rendered value.
So, you ...
- 3,400
3
votes
Reverse Assets fixedOrder
Set the order parameter to 'sortOrder desc':
{% set assets = myAssetsField.order('sortOrder desc') %}
- 36k
3
votes
Accepted
How Do I group entries by Category and retain fixed Category Order?
Twig is a templating language, and in my opinion this is pushing what it's comfortably meant to do. You might want to consider handling the heavy lifting w/ PHP by writing a small business logic ...
- 21.7k
3
votes
Accepted
Display entries tagged with specific tag(s) before other entries
You're on the right track with merging arrays of entry IDs. And to keep the sort order with your new craft.entries call there's in fact a method for that: fixedOrder(true).
- 36k
3
votes
Order "Entries Fields" by entry order
It's order('sortOrder') instead of fixedOrder(true).
{% set entries = craft.entries({
relatedTo: { sourceElement: entry, field: 'entriesFieldHandle' },
order: 'sortOrder',
limit: null
}) %...
- 36k
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 ...
- 34k
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 = ...
- 36k
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
- 36k
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 ...
- 1,378
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 ...
- 66.9k
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 ...
- 19.6k
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 ...
- 66.9k
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 ...
- 66.9k
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"...
- 85
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ordering × 89entries × 26
templating × 12
order × 11
categories × 10
relations × 10
sorting × 10
datetime × 8
craft3 × 7
matrix × 7
plugin-craftcommerce × 5
structure × 5
sections × 5
group × 5
assets × 4
tags × 3
query × 3
relatedto × 3
sort × 3
plugin-development × 2
control-panel × 2
entry × 2
cache × 2
elementcriteriamodel × 2
filter × 2