# Possible to use \`where\` with the WordCount field?

**URL:** <https://discourse.gohugo.io/t/possible-to-use-where-with-the-wordcount-field/45210>\
**Category:** support\
**Created:** [July 9, 2023, 8:52am UTC](https://discourse.gohugo.io/t/possible-to-use-where-with-the-wordcount-field/45210 "2023-07-09T08:52:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Olds](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/peter_olds/32/8165_2.png) [@Peter\_Olds](https://discourse.gohugo.io/u/Peter_Olds)\
**Post date:** [July 9, 2023, 8:52am UTC](https://discourse.gohugo.io/t/possible-to-use-where-with-the-wordcount-field/45210/1 "2023-07-09T08:52:34Z")

</div>

I’m trying to find all pages below a certain word count and trying to determine whether it’s possible to use `where` to do so.

I’ve got logic that pulls all pages that looks like this:

```auto
{{ $pages := .Site.GetPage "/some-pages" }}
{{ $pages := where $pages.Resources "Draft" false }}

```

This correctly works.

Where the directory structure is:

```auto
some-pages/
   index.md
   page-1.md
   page-2.md

```

I’m then trying to use where on `.WordCount` which is available in each subpage ie `{{ (index $pages 0).WordCount }}`.

What I’ve tried are things like:

```auto
{{ $wc := 100 }}
{{ where $pages "WordCount" "le" $wc }}
{{ where $pages ".WordCount" "le" $wc }}
// other variations

```

Is it possible to use `where` in this fashion?

EDIT: This does work, but requires a new slice and looping, my question about `where` still stands:

```auto
{{ $pageSet := .Site.GetPage "/some-pages" }}
{{ $pageSet := where $pageSet.Resources "Draft" false }}
{{ $pages := slice }}
{{ range $pageSet }}
    {{ if lt .WordCount 100 }}
        {{ $pages = $pages | append . }}
    {{ end }}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [July 9, 2023, 2:49pm UTC](https://discourse.gohugo.io/t/possible-to-use-where-with-the-wordcount-field/45210/2 "2023-07-09T14:49:59Z")

</div>

Fields such as `.WordCount`, `.FuzzyWordCount`, and `.Len` are not known until the page content is evaluated. You could use these fields in a `where` clause with v0.110.0 and earlier, but not with v0.111.0 and later. See [https://github.com/gohugoio/hugo/issues/11234](https://github.com/gohugoio/hugo/issues/11234).

For now, evaluate within the loop.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [July 11, 2023, 2:50pm UTC](https://discourse.gohugo.io/t/possible-to-use-where-with-the-wordcount-field/45210/3 "2023-07-11T14:50:40Z")

</div>

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