Skip to content

Instantly share code, notes, and snippets.

@tevashov
Last active October 27, 2022 21:56
Show Gist options
  • Select an option

  • Save tevashov/5172380 to your computer and use it in GitHub Desktop.

Select an option

Save tevashov/5172380 to your computer and use it in GitHub Desktop.
Get posts from custom tax grouped by terms (WP API) #WP
$myterms = get_terms('retouch_types', 'orderby=none&hide_empty');
foreach ($myterms as $term) {
setup_postdata($post);
$term->name;
//select posts in this category, and of a specified content type
$posts = get_posts( array(
'post_type' => 'retouch',
'tax_query' => array(
array(
'taxonomy' => 'retouch_types',
'field' => 'slug',
'terms' => $term->slug
)
)
));
// begin cycle through posts of this category
foreach($posts as $post) {
the_title();
the_excerpt();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment