1

How would I go about setting the order of entries in a "products" channel based on the value in a price within a matrix field? So for each product, there is a matrix field with columns of regular price, sale price, sale start date, sale end date, color (an option that rarely affects price anyway). But regular price and ale price are pretty well always the same regardless of how many color options there are for the given product. What I'm looking to do is basically this:

{exp:channel:entries orderby="{matrix_field:reg_price}" sort="asc" dynamic="no"}

Any way to do something like this? Do I need to first perform a query to determine what the active price is for the items in order to sort them by this field?

1

You should be able to sort by the first column of the Matrix field without doing anything special. In your example, let’s assume that regular_price is the first column within matrix_field, the code would be…

{exp:channel:entries orderby="{matrix_field}" sort="asc" dynamic="no"}

To be honest, this solution is based on code I wrote two years ago, but it does work and is in production, but Matrix will have been updated. I recall I had to save the entries again to make this work. Try it, and let me know how you go.

1
  • I suspect I may still need to do a query first, as the price to be ordered by is one of two columns in the matrix field, depending on whether the current date falls between the sale start date and sale end date - that determined which price is to be treated as "active" and then it's by that active price by which I need to order the entries. Tricky one, I suspect. – Jean St-Amand Sep 27 '13 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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