// pass term of CPT as parameter
function team_menu_list($attr){
wp_reset_query();
// assign any value here to create parameter array
$attributes = shortcode_atts( array(
'termname' => 'nba',
), $attr );
$term = $attributes['termname'];
// get all CPTs with that term
wp_reset_query();
// create argument list for query
$args = array('post_type' => 'team',
'tax_query' => array(
array(
'taxonomy' => 'sport',
'field' => 'slug',
'terms' => $term
)
),
'order' => 'ASC',
'posts_per_page' => 1000,
);
$loop = new WP_Query($args);
// create string to return via shortcode
$catstring .= '<ul>';
while($loop->have_posts()) : $loop->the_post();
$catstring .= '<li><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></li>';
endwhile;
$catstring .= '</ul>';
return $catstring;
}
add_shortcode('team_menu', 'team_menu_list');