Skip to content

Instantly share code, notes, and snippets.

@lepittenger
lepittenger / page-cpts-grouped-by-taxonomy.php
Created July 31, 2017 02:14
Loop Through CPTs + Group by Custom Taxonomy Terms
<?php
/**
*
* Loop through some custom post types and group them by taxonomy term,
* outputting the taxonomy term names before the set of posts
*
*/
// get all of the custom taxonomy terms
$taxonomy = 'my_custom_taxonomy';
@jaredkc
jaredkc / group-posts-by-terms.php
Last active April 25, 2024 03:39
Wordpress: get posts and group by taxonomy terms.
/**
* Get posts and group by taxonomy terms.
* @param string $posts Post type to get.
* @param string $terms Taxonomy to group by.
* @param integer $count How many post to show per taxonomy term.
*/
function list_posts_by_term( $posts, $terms, $count = -1 ) {
$tax_terms = get_terms( $terms, 'orderby=name');
$args = array(