Catchable fatal error: Object of class stdClass could not be converted
to string in /wp-content/themes/new/single.php on line 22
This is because $wpdb->get_row
returns an object by default and you can’t echo an object. Changing echo $toc
to echo $toc->meta_value
will give you your desired result.
Your other problem is that multiple terms can have have the same term_id. Your custom table should be using the term_taxonomy_id which will always be unique.
global $wpdb;
$term = get_term_by('id', $termID, 'dataset'); //Seems redundant does $term->term_id === $termID???
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->taxonomymeta}
WHERE `taxonomy_id` = %d
AND `meta_key` LIKE 'baseurl' ",
$term->term_id );
$toc = $wpdb->get_row( $query );
echo $toc->meta_value;