Skip to content

Instantly share code, notes, and snippets.

@IacopoC
Last active March 16, 2019 21:30
Show Gist options
  • Save IacopoC/e46fece810deb5d8fd157e1cd36965e5 to your computer and use it in GitHub Desktop.
Save IacopoC/e46fece810deb5d8fd157e1cd36965e5 to your computer and use it in GitHub Desktop.
ACF loop through news taxonomy
<?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; ?>
@IacopoC
Copy link
Author

IacopoC commented May 6, 2017

Useful loop if you use ACF plugin and you want to show specific custom post type by custom category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment