# Sorting Categories by Name

**URL:** https://meta.discourse.org/t/sorting-categories-by-name/111430
**Category:** Support
**Created:** [March 12, 2019, 10:47pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430 "2019-03-12T22:47:36Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [March 12, 2019, 10:47pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/1 "2019-03-12T22:47:36Z")

</div>

How would you sort {host}/categories by name?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 12, 2019, 11:15pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/2 "2019-03-12T23:15:42Z")

</div>

Are you trying to order categories on the Category page? If so, that can be done by enabling the `fixed category positions` Site Setting. When that setting is enabled, an option to Reorder Categories is added to the staff menu on the top-right of the category page.

If this isn’t what you’re looking for, let us know.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 13, 2019, 1:19am UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/3 "2019-03-13T01:19:30Z")

</div>

If you have more than 20 or so, a bit of ruby at the console can sort them all.

---

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [March 13, 2019, 5:09am UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/4 "2019-03-13T05:09:46Z")

</div>

Do you know off hand the field that would have to be changed?

---

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [March 13, 2019, 5:13am UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/5 "2019-03-13T05:13:54Z")

</div>

> [@simon](#):
>
> If this isn’t what you’re looking for, let us know.

That looks cool and it looks like it would work.

It doesn’t work well with Categories with SubCategories.  
Which I click on a main category to move up it doesn’t move.  
Sub categories within a main category do move.

Is that a bug?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [March 13, 2019, 7:52am UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/6 "2019-03-13T07:52:50Z")

</div>

It works here. Could be customisations interfering with the page.

---

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [March 13, 2019, 10:42pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/7 "2019-03-13T22:42:24Z")

</div>

> [@Stephen](#):
>
> It works here

It works here as long as the item above is a parent category. It fails when the item above is a subcategory.

Is there an official way I can add a test that shows the problem (or not) … do the UI tests use Puppeteer or something similar?

---

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [March 13, 2019, 11:03pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/8 "2019-03-13T23:03:07Z")

</div>

> [@Stephen](#):
>
> It works here

The issue I’m seeing is pretty much the same as [Reorder Categories behaving strangely](https://meta.discourse.org/t/reorder-categories-behaving-strangely/104190)

---

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [March 18, 2019, 9:40pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/9 "2019-03-18T21:40:06Z")

</div>

I ended up doing this via SQL.

> [@Ordering categories using SQL](https://meta.discourse.org/t/ordering-categories-using-sql/111960):
>
> The following code changes the order of categories to be alphanumeric using SQL. Preconditions. Postgres backend UPDATE categories SET POSITION = subquery.position FROM ( SELECT POSITION , CASE WHEN category\_id = 0 THEN parent\_category\_id ELSE category\_id END category\_id , CASE WHEN category\_id = 0 THEN parent\_category\_name ELSE category\_name END category\_name FROM ( SELECT ROW\_NUMBER - 1 AS POSITION , parent\_category\_id , parent\_category\_name , category\_id , category\_name F…

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 17, 2019, 9:40pm UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/10 "2019-04-17T21:40:23Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
