# Issues with limit number of posts helper

**URL:** <https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441>\
**Category:** Developer help\
**Created:** [July 28, 2019, 6:59pm UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441 "2019-07-28T18:59:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt-B](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/matt-b/32/7929_2.png) [@Matt-B](https://forum.ghost.org/u/Matt-B)\
**Post date:** [July 28, 2019, 6:59pm UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/1 "2019-07-28T18:59:27Z")

</div>

I am using the last version and last configuration of Ghost  
I am using all navigators, but essentially Safari

So, as you could see, I have two sections, the first one will be “latest news”, I achieve to code it as I wanted.

Now the second section is “events”, As you see there is a lot of posts, but I don’t want them all, I want like, 3 posts from all of them.

So, as I did for the first section I put the limit helper to 3.

But every time I put this, only one post of events is staying.

My code basically is this one:

```
        ------ Latest news start here -------
        {{#foreach posts limit="3"}}
        {{#if @first}}
        my content
        {{else}}
       {{#if @last}}
        my content
        {{else}}
        my content
        {{/if}}
        {{/if}}
        {{/foreach}}

        ----- Events start here -----
        {{#foreach posts}}. -> if I put limit="3", then only one post is here!
        {{#has tag="eventos"}}
       my content
        {{/has}}
        {{/foreach}}

```

Is that because I’m using “has” in the second part ?

I tested with the get helper too, but the same thing happened: only one post was there when I put limit=“3” !!

Thanks in advance for your help!!

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [July 29, 2019, 10:47am UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/2 "2019-07-29T10:47:23Z")

</div>

Hey there, would you mind sharing the full code here instead of pseudo code? Worried I might be missing something

---

<div class="post-metadata">

**Author:** ![Matt-B](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/matt-b/32/7929_2.png) [@Matt-B](https://forum.ghost.org/u/Matt-B)\
**Post date:** [July 29, 2019, 5:08pm UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/3 "2019-07-29T17:08:23Z")

</div>

Hi,

Thanks for your quick answer 🙂

Here is the full code:

```
{{!< default}}

{{> "featuredPosts"}}

{{> "newsletter"}}

<div id="main">
    <div class="container">
        <div class="row">
            {{#foreach posts limit="3"}}
            {{#if @first}}
                    <div class="col-xs-12 col-sm-12 col-lg-4 col-md-12">
                        <div class="post post-presentation second-post lazy {{#if feature_image}}background{{else}}background-pattern{{/if}}"
                        {{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
                            <div class="gradient gradient2">
                                <h3><a href="{{url}}">{{title}}</a></h3>
                                <div class="post-tags">
                                    {{#foreach tags limit="2"}}
                                        <a href="{{url}}">{{name}}</a>
                                    {{/foreach}}
                                </div>
                                <div class="share-icons">
                                    <div class="icon-container">
                                        {{#primary_author}}
                                            {{#if profile_image}}
                                                <a href="{{url}}" class="author-info">
                                                    <div class="author-image background lazy" data-src="{{profile_image}}"></div>
                                                </a>
                                            {{/if}}
                                        {{/primary_author}}
                                        <i class="fa fa-share d-none d-sm-block {{^if primary_author.profile_image}}ml-0{{/if}}"></i>
                                        <div class="icons d-none d-sm-block">
                                            <a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
                                            <a href="https://twitter.com/share?text={{encode title}}&amp;url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
                                            <a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
                                        </div>
                                    </div>
                                </div>
                                <div class="float-bottom">
                                    <p>{{excerpt words="15"}}...</p>
                                    <a href="{{url}}" class="btn btn-no-background">{{t "Read Post"}} <i class="fa fa-chevron-right"></i></a>
                                </div>
                            </div>
                        </div>
                    </div>
                    {{else}}
                <div class="col-xs-12 col-sm-12 col-lg-4 col-md-12">
                    <div class="post post-presentation second-post lazy {{#if feature_image}}background{{else}}background-pattern{{/if}}"
                    {{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
                        <div class="gradient gradient2">
                            <h3><a href="{{url}}">{{title}}</a></h3>
                            <div class="post-tags">
                                {{#foreach tags limit="2"}}
                                    <a href="{{url}}">{{name}}</a>
                                {{/foreach}}
                            </div>
                            <div class="share-icons">
                                <div class="icon-container">
                                    {{#primary_author}}
                                        {{#if profile_image}}
                                            <a href="{{url}}" class="author-info">
                                                <div class="author-image background lazy" data-src="{{profile_image}}"></div>
                                            </a>
                                        {{/if}}
                                    {{/primary_author}}
                                    <i class="fa fa-share d-none d-sm-block {{^if primary_author.profile_image}}ml-0{{/if}}"></i>
                                    <div class="icons d-none d-sm-block">
                                        <a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
                                        <a href="https://twitter.com/share?text={{encode title}}&amp;url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
                                        <a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
                                    </div>
                                </div>
                            </div>
                            <div class="float-bottom">
                                <p>{{excerpt words="15"}}...</p>
                                <a href="{{url}}" class="btn btn-no-background">{{t "Read Post"}} <i class="fa fa-chevron-right"></i></a>
                            </div>
                        </div>
                    </div>
                </div>
                {{#if @last}}
                <div class="col-xs-12 col-sm-12 col-lg-4 col-md-12">
                    <div class="post post-presentation second-post lazy {{#if feature_image}}background{{else}}background-pattern{{/if}}"
                    {{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
                        <div class="gradient gradient2">
                            <h3><a href="{{url}}">{{title}}</a></h3>
                            <div class="post-tags">
                                {{#foreach tags limit="2"}}
                                    <a href="{{url}}">{{name}}</a>
                                {{/foreach}}
                            </div>
                            <div class="share-icons">
                                <div class="icon-container">
                                    {{#primary_author}}
                                        {{#if profile_image}}
                                            <a href="{{url}}" class="author-info">
                                                <div class="author-image background lazy" data-src="{{profile_image}}"></div>
                                            </a>
                                        {{/if}}
                                    {{/primary_author}}
                                    <i class="fa fa-share d-none d-sm-block {{^if primary_author.profile_image}}ml-0{{/if}}"></i>
                                    <div class="icons d-none d-sm-block">
                                        <a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
                                        <a href="https://twitter.com/share?text={{encode title}}&amp;url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
                                        <a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
                                    </div>
                                </div>
                            </div>
                            <div class="float-bottom">
                                <p>{{excerpt words="15"}}...</p>
                                <a href="{{url}}" class="btn btn-no-background">{{t "Read Post"}} <i class="fa fa-chevron-right"></i></a>
                            </div>
                        </div>
                    </div>
                </div>
                {{/if}}
                {{/if}}
            {{/foreach}}

            {{#foreach posts}}
            {{#has tag="eventos"}}
                <div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
                    <div class="post post-square lazy post-presentation {{#if feature_image}}background{{else}}background-pattern{{/if}}"
                    {{#if feature_image}}data-src="{{feature_image}}"{{/if}}>
                        <div class="gradient gradient2 d-flex align-items-center">
                            <div class="float-top">
                                <div href="#" class="share-icons d-none d-sm-block">
                                    <div class="icon-container">
                                        <i class="fa fa-share"></i>
                                        <div class="icons">
                                            <a href="https://www.facebook.com/sharer/sharer.php?u={{url absolute="true"}}" onclick="window.open(this.href, 'facebook-share','width=580, height=300');return false;"><i class="fab fa-facebook-f"></i></a>
                                            <a href="https://twitter.com/share?text={{encode title}}&amp;url={{url absolute="true"}}" onclick="window.open(this.href, 'twitter-share', 'width=580, height=300');return false;"><i class="fab fa-twitter"></i></a>
                                            <a href="https://plus.google.com/share?url={{url absolute="true"}}" onclick="window.open(this.href, 'google-plus-share', 'width=580,height=300');return false;"><i class="fab fa-google-plus-g"></i></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="post-info">
                                <div class="separator"></div>
                                <h3><a href="{{url}}">{{title}}</a></h3>
                                <div class="post-tags">
                                    {{#foreach tags limit="2"}}
                                        <a href="{{url}}">{{name}}</a>
                                    {{/foreach}}
                                </div>
                            </div>
                            <div class="float-bottom">
                                {{#primary_author}}
                                <a href="{{url}}" class="vertical-align author-info">
                                    <div class="author-image background lazy {{^if profile_image}}author-image-fill{{/if}}" {{#if profile_image}} data-src="{{profile_image}}"{{/if}}""></div> {{name}}
                                </a>
                                {{/primary_author}}
                            </div>
                        </div>
                    </div>
                </div>
            {{/has}}
            {{/foreach}}

        </div>
    </div>
</div>

{{pagination}}
```

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [July 30, 2019, 10:10am UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/4 "2019-07-30T10:10:13Z")

</div>

Have you tried using the `get` helper to get 3 posts with the right tag?

> **[Ghost Handlebars Theme Helpers: get](https://ghost.org/docs/themes/helpers/get/)**
>
> Make custom queries to the Ghost API using the get helper and fetch publicly available data. Read more about Ghost themes! 👻

I think what might be happening in your case is that you’re looping through all the posts, limiting them to 3 posts and then the `has` is only allowing through 1 because there’s only 1 post tagged with `eventos` in those 3 posts. Does that make sense?

---

<div class="post-metadata">

**Author:** ![Matt-B](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/matt-b/32/7929_2.png) [@Matt-B](https://forum.ghost.org/u/Matt-B)\
**Post date:** [July 30, 2019, 5:23pm UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/5 "2019-07-30T17:23:22Z")

</div>

Hi,

Thanks for you quick answer, I tried with get helper too, but it don’t work too,

I tried to tag a least 5 posts with tag eventos, when I don’t put the limit, they all show up where I want, but when I put the limit of 3, then, only one is showing up,

I understand what you are talking about, and for avoiding this, for each section, I opened with `{{for each posts}}` and closed with `{{/foreach posts}}`

But maybe that’s not possible do do that?

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [July 31, 2019, 10:43am UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/6 "2019-07-31T10:43:33Z")

</div>

Did you move all the criteria to the `get` helper? You can put the `tag` and `limit` in there and remove the `has`. Something like this:

```auto
{{#get "posts" filter="tags:eventos" limit="3" include="tags" }}
    {{#foreach posts}}
        <h2>{{title}}</h2>
        <p>tagged: {{tags separator=", "}}</p>
    {{/foreach}}
{{else}}
    <p class="error">{{error}}</p>
{{/get}}

```

---

<div class="post-metadata">

**Author:** ![Matt-B](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/matt-b/32/7929_2.png) [@Matt-B](https://forum.ghost.org/u/Matt-B)\
**Post date:** [July 31, 2019, 9:18pm UTC](https://forum.ghost.org/t/issues-with-limit-number-of-posts-helper/8441/7 "2019-07-31T21:18:52Z")

</div>

> [@DavidDarnes](#):
>
> {{#get “posts” filter=“tags:eventos” limit=“3” include=“tags” }} {{#foreach posts}}
> 
> ## {{title}}
>  
> 
> tagged: {{tags separator=", "}}
> 
> {{/foreach}} {{else}} 
> 
> {{error}}
> 
> {{/get}}

Hi,

Thanks a lot for your help, all is working fine, maybe it was because I placed the `foreach` helper in the wrong place, it was like this when I tried with the `get` helper:

```
{{#foreach posts}}    
{{#get "posts" filter="tags:eventos" limit="3" include="tags" }}
    <h2>{{title}}</h2>
    <p>tagged: {{tags separator=", "}}</p>
{{/foreach}}
{{else}}
<p class="error">{{error}}</p>
{{/get}}
{{/foreach}}

```

It makes more sense with your order!

Thanks for all!
