Wordpress - Given a WP_Query, how can I get a list of tags?

For the sake of posterity, I ended up just iterating through the loop twice: once to get the tags, and then to actually display the page.

Here's my code:

if ( have_posts() ) :
 // get tags for found posts
 $recent_tags = array();
 while ( $loop->have_posts() ) : $loop->the_post();
  foreach(get_the_tags() as $t) $recent_tags[$t->slug] = $t->name; // this adds to the array in the form ['slug']=>'name'
 endwhile; 

 // de-dupe
 $recent_tags = array_unique($recent_tags);
 // sort
 natcasesort($recent_tags);

 // do something with the array

 while ( $loop->have_posts() ) : $loop->the_post();

 // normal wp loop

Tags:

Tags

Wp Query