Skip to content

Instantly share code, notes, and snippets.

@axxe16

axxe16/template.php

Last active Nov 5, 2020
Embed
What would you like to do?
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