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; ?>
cw-index-1-r2
goUSF-index-1
usfgm-index-1-r3
bgl-index-1
ucon-index-1-r1
adopt-index-2
skalet-index-1-r2
pcabral
th-index-1
rms-index-2
km-index-1-r1
peu-index-2-r3b
pdu-index-1-r2a
oph-index-1-r2
mmm-index-1
long-index-1-r1a
ernies-index-1
cooks-index-1-r2a
df-index-1-r1
vs-index-1
uni-index-1
pe-wedding-print
Screen shot 2013-10-25 at 3.38.39 PM
fred
cabral
dava
psa
errg
apex
pag
cwb
beginners
awakealive
ecom
ab