10
votes
Accepted
Order by score and another field
I assume you're using .search() – a common mistake is to try to combine orderBy('score') with custom fields, which doesn't work because the score attribute isn't an actual field, but a computed value ...
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 ...
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 {% ...
4
votes
Accepted
Method (plugin free?) to combine search results across multiple searches (and element types)
To get this working I submitted a patch to 'SortByField' - https://github.com/dannynimmo/craftcms-sortbyfield - to get this plugin to work with Commerce products - and I now do this:
{% set ...
3
votes
Accepted
Sorting all matrix fields from multiple entries as one list
Yes, you can do that with matrix block queries. Instead of going through entries to get the matrix blocks, you can query matrix blocks independently with a custom sort order.
{% set notesByDate = ...
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") }}' %}
{% ...
2
votes
Accepted
Multisort with supersort plugin
Try to group the entries sorted by size using the group filter:
{% set entriesSorted = entries|supersort('sortAs', '{ size }', SORT_NUMERIC) %}
{% set entriesByBrand = entriesSorted|group('brand....
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'
}...
2
votes
Accepted
Sort entries by custom date in Matrix field / Super Table
I did something like this as a workaround:
Loop over entries, fetching all data you need and adding it to an array. Sorting that array with SuperSort and than displaying all info by looping over the ...
2
votes
Accepted
Retrieve entries by random sort, then resort alphabetically
I recon Supersort is they way to go, as its got some really handy functions to make this sort of thing a breeze. Try with the following:
{% set entries = craft.entries.section('presenters').order('...
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([
'...
2
votes
Syntax for Multisort Filter
For those of you reading through this post, I thought it might be useful to provide a bit of background on my question. The Craft Docs list "multisort" under Filters and it sounded like something that ...
2
votes
Nesting level too deep - recursive dependency?
I figured this out, with help from a GitHub thread or too. It appeared that using the sort filter on an array of objects was problematic. I was able to fix this by sorting the keys in speakers instead ...
2
votes
Accepted
Sort Repeater fields alphabetically
You can use the orderBy parameter to get super table blocks in the specified order. For example, if your super table field is called countries and the title field (that you store the country's name in)...
2
votes
Accepted
sort by checkbox field with multiple options and by postDate desc
The equivalent SQL would be something like
SELECT * FROM players ORDER BY teamName IS NOT NULL DESC, postDate DESC;
but I'm not sure how that would translate in a simple element query. It'd be ...
1
vote
Orderby entry field?
Here are your options:
How to order by related entry type field
https://github.com/craftcms/cms/issues/6010
If you use the logic of the 1st variant, then it should come out something like this:
{# ...
1
vote
Accepted
How to sort database values using other variable
Worth mentioning first that Element Queries have a fixedOrder parameter available to them (https://craftcms.com/docs/commerce/4.x/products-variants.html#product-fixedorder)... however from looking at ...
1
vote
sort by checkbox field with multiple options and by postDate desc
I believe this won't work the way you want it with a single query, especially with reliable performance. The problem is that you actually want 2 different sort criteria being combined.
I would ...
1
vote
Accepted
Order matrix blocks by date field
I hope I am not completely missing the point, but I guess like that:
Initial 5:
{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').limit(5).all() %}
{{ ...
1
vote
Order grouped results by dropdown order
You could wrap this in another for loop and put a condition on the inner fors,
something like
{% for option in myPositionDropdown %}
<h2>{{ option.value }}</h2>
{% for position, ...
1
vote
Accepted
Help with correct syntax regarding multisort please
Try removing the quotes on 2nd/3rd arguments:
{% set rides = furniture|multisort(furniture['price'],[SORT_DESC],[SORT_REGULAR]) %}
1
vote
How to reorder structure entries in the Admin panel?
I don't know if there's a quick/easy way to do this within the admin area, but if you go to Entries, then click on your Structure, there's a little 4-dot symbol to the left of the Entry's title (make ...
1
vote
Syntax for Multisort Filter
I think this should do what you're looking for:
{% for rides in allRides|multisort(['eventDate'],['SORT_DESC'],['SORT_REGULAR']) %}
1
vote
Accepted
Extend order methods to sort numbers naturally
It's possible to pass MySQL functions to the order parameter. Using the MySQL LENGTH function, I believe the following should do the trick (assuming your "model number" field's handle is modelNumber):
...
1
vote
Craft Commerce: Sort products by Sale price
Any update on this one? Is it possible to sort the products based on the (default variant) salePrice instead of the (default variant) defaultPrice?
Thank you
1
vote
Sorting by date field across sections not working
Your second attempt is sound. I don’t really have an idea why it doesn’t work, but I bet it has to do with the SQL that is caused by setting the section param to an array.
What I would try next is ...
1
vote
Sort entries by custom date in Matrix field / Super Table
I used the preparse plugin to save a date value from a SuperTable field into a static field as 'yyyymmdd'. I could then sort my entries based on that static field.
1
vote
Method (plugin free?) to combine search results across multiple searches (and element types)
You could do all of this in PHP. Build your criteria models, merge the results and sort them with usort.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sort × 24order × 9
entries × 6
matrix × 4
array × 4
categories × 3
datetime × 3
ordering × 3
sorting × 3
group × 3
plugin-supersort × 3
plugin-craftcommerce × 2
filter × 2
plugin-supertable × 2
multisort × 2
craft3 × 1
templating × 1
search × 1
structure × 1
entries-field × 1
ecommerce × 1
yii × 1
merge × 1
blocks × 1
filtering × 1