How do I create a list of related listings

Hi,

I am using the Directory plugin and have a number of listings in categories. Within those listings some have tags on them.

I have a requirement to display a list of 'related' list items when on the single-listing screen.

I found some code for creating a shortcode which handles related items but it isn't working because the following line is returning nothing.

$tags = wp_get_post_tags($post->ID);

The full source is :

function related_posts_shortcode( $atts ) {
	extract(shortcode_atts(array(
	    'limit' => '5',
	), $atts));

	global $wpdb, $post, $table_prefix;

	if ($post->ID) {
                $retval = '
<ul>';
 		// Get tags
                $tags = wp_get_post_tags($post->ID);
                $tagsarray = array();
		foreach ($tags as $tag) {
			$tagsarray[] = $tag->term_id;
		}
		$tagslist = implode(',', $tagsarray);

		// Do the query
		$q = "SELECT p.*, count(tr.object_id) as count
			FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p
                        WHERE tt.taxonomy ='listing_tag'
                                AND tt.term_taxonomy_id = tr.term_taxonomy_id
                                AND tr.object_id  = p.ID
                                AND tt.term_id IN ($tagslist)
                                AND p.ID != $post->ID
				AND p.post_status = 'publish'
				AND p.post_date_gmt < NOW()
 			GROUP BY tr.object_id
			ORDER BY count DESC, p.post_date_gmt DESC
			LIMIT $limit;";

		$related = $wpdb->get_results($q);
 		if ( $related ) {
			foreach($related as $r) {
				$retval .= '
<li><a>post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>
';
			}
		} else {
			$retval .= '

<li>No related posts found</li>
';
		}
		$retval .= '</ul>
';
		return $retval;
	}
	return;
}
add_shortcode('related_posts', 'related_posts_shortcode');

When I go in to look at the listings I can see that they have tags applied to them, but they don't come out using wp_get_post_tags();

Could you let me know how I need to extract the tags from the directory listing posts?

Thanks,
Neil.