Feature Most Recent Custom Post Type in Specific Custom Taxonomy Term

For some of my projects, I like to feature the most recent addition to a specific custom taxonomy in either a sidebar or footer area. In order to do this, you’ll create a custom post type with a custom taxonomy. Just use this code below in whatever file necessary in order to filter through your post types and feature only the most recent addition in a specific taxonomy.

In the example below, I’m listing the most recent project with the industry of “recent.”

Recent Work

    <?php $recent = new WP_Query(array('post_type' => 'projects', 'posts_per_page' => -1, 'portfolio-industry' => get_the_term_list($post->ID, 'portfolio-industry'))); $number = 0; while($recent->have_posts()) : $recent->the_post();?> <?php if ((has_term('Recent', 'portfolio-industry')) && ($number == 0)) {?> <li><a href="<?php the_permalink();?>"><?php the_title();?></a></li> <?php $number++; };?> <?php endwhile; ?>