$termtax = $wpdb->get_results(
"SELECT term_taxonomy_id
FROM wp_term_relationships
WHERE object_id = '".$postid."'",
ARRAY_N
);
function array_values_recursive($thearray)
{
$newtermtax = array();
foreach ($thearray as $value)
{
if (is_scalar($value) OR is_resource($value))
{
$newtermtax[] = $value;
}
elseif (is_array($value))
{
$newtermtax = array_merge($newtermtax, array_values_recursive($value));
}
}
return $newtermtax;
}
$newnewtermtax = implode(", ", array_values_recursive($termtax));
$termid = $wpdb->get_var(
"SELECT term_id
FROM wp_term_taxonomy
WHERE term_taxonomy_id
IN (".$newnewtermtax.")
AND taxonomy = 'wpfc_prc"
);
Obviously you have to use backticks around all the tables column names.
Also, anyone reading this to help them, remember, when inserting a string into a table do not forget to use addslashes() to ensure all characters that need to be ‘escaped’, are escaped.
This is a noob error, and one that took me 20mins to realise I had made.
Thanks, Josh.