Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 18, 2023 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/06f77e1a5d9d8fd92ef78fa52159daed to your computer and use it in GitHub Desktop.
Save zackpyle/06f77e1a5d9d8fd92ef78fa52159daed to your computer and use it in GitHub Desktop.
Output posts separated by category using Loops & Logic plugin - Example using a Team and Team Category #loopsandlogic #l&l
<!-- Team CPT (team_member), and Team Category (team_category) - Separeted into their categories -->
<!-- Note: In this case, the order of the taxonomy matters, so we will use a plugin to set
menu order of team_category and use orderby=menu_order to respect that order instead of just outputting it in alpha order -->
<Loop type=taxonomy_term taxonomy=team_category orderby=menu_order>
<h2><Field title /></h2>
<Loop type=team_member taxonomy=team_category terms="{Field id}">
<Field title />
</Loop>
</Loop>

The output would look something like this with each term in team_category and the posts in that category below each:

Executive Team

Jane Doe
John Smith

Management

Tom Johnson
Angie Mark

Engineering

Jill Mitchell
George Jackson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment