Function to grab the ID of a custom taxonomy

I am stuck on this one and would be grateful if someone pointed out what I am missing.

Here is my situation: I’ve got a custom taxonomy called venues and I’ve added custom meta to that taxonomy via a custom table called $wpdb->venuesmeta which looks like this:

meta_idvenues_idmeta_keymeta_value
14address9009 W Sunset Blvd
2015address1401 Santa Monica Blvd

Just a quick two cell example (there is more in there).

Ok. So in certain circumstances, or rather most of the time I am querying the table if only pulls the first cell which happens to be 4.

I created this function which fixed the problem most of the time:

function get_venues_id_by_key( $meta_key ) {
	global $wpdb;
	
	$venue = $wpdb->get_var( $wpdb->prepare( "SELECT venues_id FROM $wpdb->venuesmeta WHERE meta_key = %s", $meta_key ) );
	
	if ( $venue != '' ) {		
		$venue_id = (int)$venue;
		return $venue_id;
	}		
	
	return false;
}

Where I am using it like $address = get_metadata( 'venues', get_venues_id_by_key( 'address' ), 'address', true );.

But in the front end when on a taxonomy in venues like /venues/$tax_name/. It’s still querying the first cell and not the current ID.

So I thought I need to compare the venuesmeta table to the term_taxonomy and can’t seem to get that code working proper. The term_taxonomy table would be:

term_taxonomy_idterm_idtaxonomydescriptionparentcount
33venues01
44venues03

Just a quick two cell example of the term_taxonomy (there is more in there).

So in order to to pull in the $tax for ID of 3, I thought to do a compare of the above function to the term_taxonomy table, but only got to this function, guess this is where i need help..

function get_venues_id_by_key_match( $meta_key ) {
	global $wpdb;
	
	$venue = $wpdb->get_var( $wpdb->prepare( "SELECT venues_id FROM $wpdb->venuesmeta WHERE meta_key = %s AND term_id FROM $wpdb->term_taxonomy WHERE taxonomy = venues", $meta_key ) );
	
	if ( $venue != '' ) {		
		$venue_id = (int)$venue;
		return $venue_id;
	}		
	
	return false;
}