# Sort posts from more sections

**URL:** https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366
**Category:** support
**Created:** [November 17, 2018, 8:58pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366 "2018-11-17T20:58:47Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![trepik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/trepik/32/7350_2.png) [@trepik](https://discourse.gohugo.io/u/trepik)
#### Post date: [November 17, 2018, 8:58pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/1 "2018-11-17T20:58:47Z")

</div>

On my homepage I’m usign pagination and I want to display posts from two section ordere by date. However, the order is kept within the sections but one older post from one section is above some younger posts from the other section. Here is the code I’m using:

```auto
{{ $paginator := .Paginate (where (where .Site.Pages "Section" "in" (slice "flash" "story") ) "IsPage" true) }}
{{ range $index, $element := .Paginator.Pages.ByDate.Reverse }}

```

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [November 18, 2018, 1:44am UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/2 "2018-11-18T01:44:27Z")

</div>

On the 2nd line, try replacing `.Paginator` with the `$paginator` variable you declared (untested)

---

<div class="post-metadata">

### Author: ![trepik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/trepik/32/7350_2.png) [@trepik](https://discourse.gohugo.io/u/trepik)
#### Post date: [November 18, 2018, 8:42pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/3 "2018-11-18T20:42:49Z")

</div>

I’ve already tried what you suggest, but no post are displayed then, the page stays empty.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [November 19, 2018, 3:28pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/4 "2018-11-19T15:28:48Z")

</div>

I would have to see your code to troubleshoot further.

But on my laptop, given this content structure:

```auto
├── content
│ ├── flash
│ │ ├── flash1.md
│ │ └── flash2.md
│ ├── nope
│ │ ├── nope1.md
│ │ └── nope2.md
│ └── story
│ ├── story1.md
│ └── story2.md

```

And this template code:

```auto
{{ $paginator := .Paginate (where (where .Site.Pages "Section" "in" (slice "flash" "story") ) "IsPage" true) }}

<ul>
{{- range $index, $element := $paginator.Pages.ByDate.Reverse }}
  <li><a href="{{ .Permalink }}">{{ .Title }} -- {{ .Date }}</a></li>
{{- end }}
</ul>

```

I get this output:

```auto
<ul>
  <li><a href="http://example.org/story/story2/">Story2 -- 2018-11-19 09:14:27 -0600 CST</a></li>
  <li><a href="http://example.org/story/story1/">Story1 -- 2018-11-19 09:14:27 -0600 CST</a></li>
  <li><a href="http://example.org/flash/flash2/">Flash2 -- 2018-11-19 09:14:27 -0600 CST</a></li>
  <li><a href="http://example.org/flash/flash1/">Flash1 -- 2018-11-19 09:14:01 -0600 CST</a></li>
</ul>

```

---

<div class="post-metadata">

### Author: ![trepik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/trepik/32/7350_2.png) [@trepik](https://discourse.gohugo.io/u/trepik)
#### Post date: [November 20, 2018, 8:28pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/5 "2018-11-20T20:28:11Z")

</div>

Thanks for trying to help realy appreaciate it.  
Actually on the first page of the paginator the content is ordered by date correctly.  
The issue is that on the second page of the paginatior is some younger content than the last one on the first page.

```
page1
flash5 (2018-11-20)
flash4 (2018-11-19)
story1 (2018-08-15)

page2
flash3 (2018-10-15)
flash2 (2018-10-03)
flash1 (2018-08-04)
```

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [November 20, 2018, 8:35pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/6 "2018-11-20T20:35:39Z")

</div>

I see. So, you will need to share your code for me to troubleshoot further.

If you can’t do that, then create a sample repo that reproduces your issue, then share that.

---

<div class="post-metadata">

### Author: ![trepik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/trepik/32/7350_2.png) [@trepik](https://discourse.gohugo.io/u/trepik)
#### Post date: [November 20, 2018, 8:43pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/7 "2018-11-20T20:43:21Z")

</div>

> **[trepik/rodinka](https://github.com/trepik/rodinka/tree/master)**
>
> Contribute to trepik/rodinka development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [November 20, 2018, 9:29pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/8 "2018-11-20T21:29:42Z")

</div>

Okay I see the line you’re talking about now, but I’m not sure how to fix. Perhaps someone else more familiar with pagination can help you.

> <https://github.com/trepik/rodinka/blob/master/layouts/partials/portfolio.html#L5>

---

<div class="post-metadata">

### Author: ![trepik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/trepik/32/7350_2.png) [@trepik](https://discourse.gohugo.io/u/trepik)
#### Post date: [November 20, 2018, 9:36pm UTC](https://discourse.gohugo.io/t/sort-posts-from-more-sections/15366/9 "2018-11-20T21:36:00Z")

</div>

Actually I figured it out… by adding `.ByDate.Reverse` in the the first line (L4), where the paginator is created … thanks anyway for your help.
