Replicating the prev_post helper with #get

I don’t know if this is a bug or a misconfiguration, but I’m trying to replicate the prev_post helper with #get, but I don’t have the results I expect… :disappointed_relieved:

I want to extend the prev_post helper for a use case not supported by prev_post, but first, I need to make sure I’m able to achieve the same results. I’ve been banging my head against the wall for a few hours…

Is there something I did wrong? :thinking:

Steps to Reproduce

  1. Create partials/prev_post.hbs with content below
  2. Create partials/next_post.hbs with content below
  3. Inside post.hbs, include the previous partials {{> prev_post }}{{> next_post }}
  4. Create and publish empty posts
    1. First post
    2. Second post
    3. Third post
  5. For each post, check if the partials returns the expected results

Code for partials/prev_post.hbs

{{#get "posts"
       filter="slug:-{{slug}}+published_at:<='{{published_at}}'"
       include="author,authors,tags,tiers"
       limit="1"
       order="published_at asc"
as |previousPost|
}}
  {{#previousPost}}
    <a href="{{url}}">
      <section>
        <h5>A || {{t "Older Post"}}</h5>
        <h3>{{title}} [{{published_at}}]</h3>
      </section>
    </a>
  {{/previousPost}}
{{/get}}

{{#prev_post}}
  <a href="{{url}}">
    <section>
      <h5>B || {{t "Older Post"}}</h5>
      <h3>{{title}} [{{published_at}}]</h3>
    </section>
  </a>
{{/prev_post}}

Code for partials/next_post.hbs

{{#get "posts"
       filter="slug:-{{slug}}+published_at:>'{{published_at}}'"
       include="author,authors,tags,tiers"
       limit="1"
       order="published_at desc"
as |nextPost|
}}
  {{#nextPost}}
    <a href="{{url}}">
      <section class="prev-next-title">
        <h5>C || {{t "Newer Post"}}</h5>
        <h3>{{title}} [{{published_at}}]</h3>
      </section>
    </a>
  {{/nextPost}}
{{/get}}

{{#next_post}}
  <a href="{{url}}">
    <section>
      <h5>D || {{t "Newer Post"}}</h5>
      <h3>{{title}} [{{published_at}}]</h3>
    </section>
  </a>
{{/next_post}}

Expected results

  1. First post (C = D)
    1. Previous post: none
    2. Next post: Second post
  2. Second post (A == B and C == D)
    1. Previous post: first post
    2. Next post: Third post
  3. Third post (A == B)
    1. Previous post: Second post
    2. Next post: none

Current results

  1. First post (A should be null AND C is null)
    1. Previous post: Second post
    2. Next post: none
  2. Second post (A == B AND C is null)
    1. Previous post: First post
    2. Next post: none
  3. Third post (A == B)
    1. Previous post: First post
    2. Next post: none

Setup information

Ghost Version
4.47.1

Node.js Version
v14.19.1

How did you install Ghost?
*Docker *

Provide details of your host & operating system
Docker on Windows 10

Database type
SQLite 3

You may need to adjust the {{published_at}} output so it matches the format used in filter params.

{{date published_at format="YYYY-MM-DD HH:mm:ss"}}

I’ll give it a try tonight, but I’m a bit surprised at your answer, since the #get documentation currently recommends against using the date helper inside a filter. :thinking:

Tip: To filter based on dates, use the data attributes, e.g. {{published_at}} , not the {{date}} helper, as helper functions do not get called inside of a filter.

Has this feature been fixed recently?

OK, then what I suggested won’t work.