Combining GroupByDate and Type in range

I need to combine GroupByDate and Type. ‘Where’ seems to have no effect when combined with GroupByDate:

{{ range $index, $value := (.Site.Pages.GroupByDate “January 2006” ) (where .Site.Pages “Type” “post”) }}

Context: I am building a collapsible list where posts are grouped by date. Everything is working fine except I am getting dates with no posts (because it’s currently iterating over all content. If this is narrowed down to Type=post then in theory my problem will be solved.

<!-- accordion start -->
          <div class="panel-group" id="accordion1">
            <div class="panel panel-default">
              <div class="panel-heading">
                <h4 class="panel-title">
                  <a data-toggle="collapse" data-parent="#accordion1" href="#collapseTwo">
                  Archive</a>
                </h4>
              </div>
              <div id="collapseTwo" class="panel-collapse collapse">
                <div class="panel-body">
                  <!-- Here we insert another nested accordion -->
                  <div class="panel-group" id="accordion2">
                  {{ range $index, $value := (.Site.Pages.GroupByDate "January 2006" ) (where .Site.Pages "Type" "post") }}
                    <div class="panel panel-default">
                      <div class="panel-heading">
                        <h4 class="panel-title"><a data-toggle="collapse" data-parent="#post-month-{{$index}}" href="#post-month-{{$index}}">
                          {{ .Key }}
                        </a></h4>
                      </div>
                      <div id="post-month-{{$index}}" class="panel-collapse collapse">
                        <div class="panel-body">
                          {{ range $element := (where .Pages "Type" "post") }}
                          {{ if ne . $ }}
                              <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
                          {{ end }}
                          {{ end }}
                        </div>
                      </div>
                    </div>
                    {{ end }}
                  </div>
                  <!-- Inner accordion ends here -->
                </div>
              </div>
            </div>
          </div>
          <!-- accordion end -->

Try this:

{{ range $index, $value := where (.Site.Pages.GroupByDate "January 2006" ) "Type" "post" }}

Thanks but this gives me the following error:

ERROR: 2016/04/14 Error while rendering page LinkedIn Article 5.md: template: post/single.html:76:47: executing “post/single.html” at <where (.Site.Pages.G…>: error calling where: Type isn’t a field of struct type hugolib.PageGroup

Oops. Forgot about PageGroup. Try this…

{{ range $index, $value := (where .Site.Pages "Type" "post").GroupByDate "January 2006" }}

@moorereason Many thanks. All working as expected with the code you listed.