Last active
March 16, 2019 21:30
-
-
Save IacopoC/e46fece810deb5d8fd157e1cd36965e5 to your computer and use it in GitHub Desktop.
ACF loop through news taxonomy
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 | |
$terms = get_the_terms( $post->ID, 'area'); | |
$postid = get_the_ID(); | |
foreach ($terms as $term) { | |
$posts = get_posts(array( | |
'posts_per_page'=> -1, | |
'post_type' => 'news', | |
'orderby' =>'ID', | |
'area' => $term->name, | |
'post__not_in' =>array($postid) | |
)); | |
} | |
if( $posts ): ?> | |
<ul> | |
<?php foreach( $posts as $post ): | |
setup_postdata( $post ); | |
?> | |
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> | |
<p class="txt-works"><?php echo custom_field_excerpt();?></p> | |
<?php endforeach; ?> | |
</ul> | |
<?php wp_reset_postdata(); ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful loop if you use ACF plugin and you want to show specific custom post type by custom category.