Score:-1

Sorting Custom Content Type

mx flag

Apologies if this question has been asked but I can't seem to find an answer anywhere. I am looking to sort a content type called biography. My understanding is that this is likely a custom entity and does not come with Drupal Core.

We currently use it to add leadership information such as (ceo, assistant, admin) position. Currently, the sorting function in views is standard (ascending -authored on) so new biography content is added to the bottom of a page block.

I do not have permission to download any new modules but want to create a custom sort in a hierarchy format (the highest job title first - i.e. ceo).

Can someone share how I might be able to do this? I assume it would be the same as sorting article nodes

leymannx avatar
ne flag
Hey wilson please try to make this a reproducible issue. Right now I don't have any clue what you are actually talking about. Like biographies is not part of Drupal core. Could be a custom entity, could be a taxonomy terms, maybe displayed in a view, which is configured god knows how. Please update your question and add a detailed description that also helps others later with the same problem finding a possible solution. Many thanks
mx flag
@leymannx thanks for the feedback! I inherited the site and haven't worked with this content type before and limited knowlege of drupal from this end. I assume it's very similar to Article Nodes. It is used to organize biographical information: job title, headshot, etc. It is displayed in views. There are no taxonomy terms attached fields. Just organized by sort criteria as authored on. I hope this helps!
cn flag
How do you actually want to sort it? If you are trying to change the sorting in the view, then as long as you are editing the correct view, you can just change the sorting criteria as you like in the Views editor.
mx flag
@PatrickKenny I want to sort by job title with the CEO (first), Executive Assistant (second), and so on. There's no option for that in views. Only sort ascending and sort descending. Again backend knowledge is limited. So please direct me if I'm missing something
Score:0
cn flag

First, go to the edit page for the view.

There, under Sort criteria, you will find an Add button.

If you click the Add button, a window will appear that lists all the fields you can use to sort the view. If Job title is a field, you can add it as a sort criteria and then sort by that field.

How you can sort by that field depends on what type of field it is. For a standard text field, you will only be able to sort ascending/descending; this is because Drupal has no way to tell what the order is.

If you want to set the order of the fields such as

  1. CEO
  2. Executive Assistant
  3. CFO

then this will not work if you are using a text field.

How to do it with taxonomy

One good way to do this is:

  1. Create a taxonomy vocabulary, Job title.
  • Assign weights to the taxonomy terms in the order you want them to be sorted.
  1. Add the taxonomy vocabulary as an entity reference field to the Biography content type.
  2. Add a relationship to the referenced taxonomy vocabulary to the view.
  3. As the sort criteria, use the referenced taxonomy term weight.

A simpler way

Another way to do this that is faster to set up but that will be harder to maintain down the line is to give up on sorting by the text field and add a custom weight field to the content type.

Specifically:

  1. On the Biography content type "manage fields" page, add a new Integer field. Call it something like weight or sort.
  2. On "Manage display" for the Biography content type, hide the weight field. (because we do not want to show this field)
  3. Now the annoying part-- you have to edit all Biography content and assign the weight manually.
  4. Then, in your view, as the sort criteria, sort by weight (ascending or descending, whichever makes sense for the way you assigned weights).

Obviously, when assigning weights manually like this it is easy to make a mistake, so I don't recommend this way, but it is probably the fastest way to get what you want.

mx flag
@PATRICKENNY It worked! I used taxonomy since you said it was a good way and boom. Thank you!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.