Skip Navigation

[Resolved] How to group posts output with a View by taxonomy term?

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client wants to output posts grouped by taxonomy term, like so:

Vol Number 1
• Newsletter name A
• Newsletter name B

Vol Number 2
• Newsletter name C
• Newsletter name D

Solution:
This requires two Views.

The outer View is a taxonomy View (which lists taxonomy terms).

In the output section the title of each term is displayed and a second, nested, View is inserted.

This second View displays posts, and includes a Query Filter to only show posts where the taxonomy term is set by the outer View.

0% of people find this useful.

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by Yoshifumi Yamada 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1108184

Now I have a simple code in the view editor like this....

Loop Editor>>>>

[wpv-layout-start]
[wpv-items-found]
[wpv-post-taxonomy type="vol_number"]
<!-- wpv-loop-start -->
<ul class="wpv-loop js-wpv-loop">
<wpv-loop>

  • [wpv-post-body view_template="Loop item in Newsletter View"]
  • </wpv-loop>

    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
    [wpml-string context="wpv-views"]No items found[/wpml-string]
    [/wpv-no-items-found]
    [wpv-layout-end]

    Loop item in Newsletter View>>>>

    [wpv-post-link]

    I expect this will produce like this page....

    Vol Number 1
    • Newsletter name A
    • Newsletter name B

    Vol Number 2
    • Newsletter name C
    • Newsletter name D

    However the result is just like this...

    • Newsletter name A
    • Newsletter name B
    • Newsletter name C
    • Newsletter name D

    What's wrong with my code?
    Please advise me.

    #1108261

    Nigel
    Supporter

    Languages: English (English ) Spanish (Español )

    Timezone: Europe/London (GMT+00:00)

    You need a Taxonomy View (a View which returns the terms of a taxonomy, not posts with some taxonomy) to produce a list of terms for your vol_number taxonomy.

    (In the Content Selection of your View, choose taxonomy > vol_number.)

    If you output the taxonomy name in the Loop Editor section it will give you a list like:

    Vol Number 1
    Vol Number 2
    Vol Number 3 etc.

    You then insert a second View nested in the Loop Editor.

    This second View is a normal post View (as per your own example), except it includes a Query Filter to only show posts where the vol_number term is set by the outer View.

    So for each vol_number in the outer View, the inner View will list the matching posts.

    #1108716

    Thanks! Great help!