I have to list all posts from a Wordpress custom post type and show only the title and his respective category created through a custom taxonomy. My code is here and I am with some problems at taxonomies.
<?php
$args = array(
'post_type' => 'books',
'posts_per_page' => -1);
$myposts = get_posts( $args );
$terms = get_the_terms( $post->ID , 'category' );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<h1><?php echo the_title(); ?></h1>
<p>Category: <?php echo $term->name; ?></p>
<?php endforeach;
wp_reset_postdata();?>