2

I'd like to do a more complex sorting on my Drupal 7 View. Specifically, I'd like to sort by a particular field alphabetically (easy - that's the default). However, before the View sorts the field I want it to strip out (a predefined) set of words at the beginning of the field (if they exist) such as the word 'the' or 'a' and sort based on the words that follow.

Does anyone know if this is possible?

My workaround will be to just create a 'sort by' field in the content type.

2
  • +1 Good question. It can be done in MySQL using temporary column at query time: MySQL Sort Alphabetically but Ignore “The”. Interesting to see if there will be a good answer to this. – J. Reynolds Mar 4 '16 at 6:17
  • Thanks for the suggestion - it's a good idea. I'll try the given answer first and if that doesn't meet our needs this is a good workaround. – Sage Mar 9 '16 at 0:50
3

Have you tried Views Natural Sort -module?

Provides a views filter that sorts node titles by a more natural manner by ignoring articles like "The" and "A."

Not sure if it matches your needs because of "sorts node titles" and in your question you talk about particular field. But maybe you should try it?

At least you can get base for custom module if you need to build one.

2

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.