Last active
November 5, 2020 13:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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