I have taken a few stabs at this and have hit a road block. I will try to be as descriptive as possible...
- I have a Custom Post Type: Bars
- I have a Custom Taxonomy associated with Bars called: Location
- Location has several cities associated with it. e.g. Dallas, Atlanta, Philadelphia, etc.
I have a created a shortcode that currently works with the exception that I cannot figure out how to grab the "terms" associated with "location" and display them in the Recent Post list on the front-end. Only the Thumbnail, Title, and Date are displaying.
Currently I am using wp_get_recent_posts
but after some reading, should I be using that at all? Or should I be using WP_Query
?
Here is my code:
function recent_cpt_list_display( $atts ) {
$atts = shortcode_atts( array(
'cpt_type' => 'bars',
'show_posts' => 5,
'cpt_cat' => 'location',
), $atts, 'cpt-recent-posts' );
global $post;
$cpt_type = $atts['cpt_type'];
$show_posts = $atts['show_posts'];
$cpt_cat = $atts['cpt_cat'];
$cpt_posts = wp_get_recent_posts( array(
'post_type' => $cpt_type,
'orderby' => 'date',
'order' => 'ASC',
'numberposts' => $show_posts
));
if ( ! empty( $cpt_posts ) && ! is_wp_error( $cpt_posts ) ) {
$output = '<ul class="cpt-recent-posts">';
foreach( $cpt_posts as $cpt_post ){
$output .= '<li>';
$output .= '<div class="cpt-recent-posts-thumb">' . get_the_post_thumbnail( $cpt_post['ID'], 'thumbnail' ) . '</div>';
$output .= '<div class="cpt-recent-meta">';
$output .= '<a href="' . get_permalink( $cpt_post["ID"] ) . '" title="' . esc_attr( $cpt_post["post_title"] ) . '" >' . $cpt_post["post_title"].'</a>';
$output .= '<div class="cpt-meta">' . NEED TO OUTPUT LOCATION HERE . '</div>';
$output .= '<div class="cpt-post-date">' . get_the_time( get_option( 'date_format' ), $post->ID ) . '</div>';
$output .= '</div></li>';
}
$output .= '<ul>';
}
return $output;
}
add_shortcode( 'cpt-recent-posts', 'recent_cpt_list_display' );
Any insight as to do this better, I am all ears as I am still learning. I am trying to rely less on using plugins for everything and really want to code as much as possible.
Thanks in advance.