Title says it all. I'm trying to link to the most recent post of a custom post type, but only within the same term. Currently my code successfully echos the correct term ID but doesn't show a link on the screen.
<?php
// Get the ID of the current posts's term
$terms = get_the_terms( get_the_ID(), 'comic-series' );
// Only get the parent term and ignore child terms
foreach ( $terms as $term ){
if ( $term->parent == 0 ) {
// Echo the term (this is only for debugging purposes)
echo $term->term_id;
// Take only the most recent post of same term
$args = array( 'numberposts' => '1', 'category' => $term->term_id );
$recent_posts = wp_get_recent_posts( $args );
// Link to most recent post of same term
foreach( $recent_posts as $recent ){ ?>
<a href="<?php get_the_permalink( $recent->ID ); ?>">
>>
</a> <?php
}
}
}
?>