Skip to content

Instantly share code, notes, and snippets.

@axxe16
Last active November 5, 2020 13:37
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 axxe16/dcd86b832f9b44648c46b21a4d0bef7e to your computer and use it in GitHub Desktop.
Save axxe16/dcd86b832f9b44648c46b21a4d0bef7e to your computer and use it in GitHub Desktop.
Loop che cicla una custom taxonomy e tutti i post relativi #loop #wp #custom_taxonomy #custom_type
<?php
$cat_ricette = get_terms( 'categorie' );
foreach ( $cat_ricette as $cat_ricetta ) {
$query = new WP_Query( array(
'post_type' => 'ricette',
'posts_per_page' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'categorie',
'field' => 'slug',
'terms' => array( $cat_ricetta->slug ),
'operator' => 'IN'
)
)
) );
?>
<h2><?php echo $cat_ricetta->name; ?></h2>
<?php
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<h3><a href="<?php echo get_the_permalink(); ?>"><?php echo the_title(); ?></a></h3>
<?php endwhile; endif; ?>
<?php
// Reset things, for good measure
$query = null;
wp_reset_postdata();
wp_reset_query();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment