It all boils down to WP_Query in the end even if you use get_posts, here’s my modified version:
$hasposts = get_posts('post_type=sc-events&category=40');
if( !empty ( $hasposts ) ) {
..// show the drop down menu
}
or
$query = new WP_Query(array(
'post_type' => 'sc-events',
'category' => 40
));
if( $query->have_posts() ){
echo 'we have posts';
} else {
echo 'no posts found';
}
While this will work, there’s an alternative inspired by your own answer that uses the category slug rather than its ID:
$term = get_term_by('name', 'whatever category 40 is called', 'category');
if($term != false ){
if($term->count > 0 ){
// we have posts
}
}