I can’t seem to get the categories for a custom post in the loop I have as per the code below: Can anyone help me with what I am doing wrong please?
<?php
$ids = array();
$pages = get_pages("child_of=".$post->ID);
if ($pages) {
foreach ($pages as $page) {
$ids[] = $page->ID;
}
}
$paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
$args = array(
"paged" => $paged,
"post__in" => $ids,
"posts_per_page" => 50000,
"post_type" => "knowledge_capsules",
"orderby" => "date",
"order" => "DESC"
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>
<div class="kcIndex_feedItemWrapper" id="postID<?php echo get_the_ID(); ?>">
<!-- Need to add in the lightbox content here and fire it open on click -->
<a href="#" data-featherlight="#IssueExpandedContent_<?php echo get_the_ID(); ?>">
<img src="<?php the_field('knowledgecapsule_teaser_thumbimg'); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>">
<h4><?php the_title(); ?></h4>
<div class="categoriesHere">
<?php
$terms = get_the_terms( get_the_ID(), 'knowledge_capsules' );
if(!empty($terms)){
foreach($terms as $term){
echo $term->name.'<br>';
}
}
?>
</div>
</a>
<!-- Expanded content -->
<div id="IssueExpandedContent_<?php echo get_the_ID(); ?>">
<?php the_field('knowledgecapsule_teaser_embeddcode'); ?>
<p class="viewFullVideoLink"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">View the full video</a></p>
</div>
</div>
</div>
<?php endwhile; else: ?>
<!--<h2>Oh No!!</h2>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>-->
<?php endif; ?>