Hi I have developed a shortcode that lists posts from a custom post type depending upon taxonomy terms. But I am having an issue. It's displaying all posts from all terms instead of the terms being called.
The code is below:
function course_listings( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'course_category' => '',
), $atts )
);
// Code
$args = array(
'post_type' => 'modules',
'tax_query' => array(
'taxonomy' => 'courses',
'field' => 'slug',
'terms' => $course_category
)
);
$mod_query = new WP_Query( $args );
$output='<div class="course-listings">';
while ( $mod_query->have_posts() ) {
$mod_query->the_post();
$output .='<ul>';
$output .='<li>' .get_the_title(). '</li>';
$output .='</ul>';
}
wp_reset_postdata();
$output .='</div>';
return $output;
}
add_shortcode( 'course', 'course_listings' );
Any help will be highly appreciated.
Thanks.