Every now and then we need to create a list of taxonomies that are not just empty, but are also not found in the posts for that page.
I recently found a pretty sweet solution over on Stack Overflow and wanted to share.
Limit get_terms by Posts
$my_query = new WP_Query( $my_args );
$post_ids = wp_list_pluck( $my_query->posts, 'ID' );
$my_terms = get_terms( array(
'taxonomy' => 'my-terms',
'hide_empty' => true,
'object_ids' => $post_ids,