Thanks so much, the idea to echo the $sql part was genius! Just in case anyone’s reading this the only problem I had then was trimming the white space that was appearing in front of the $mytitle when the variable was generated. I added
function af_titledespacer($title) {
return trim($title);
}
add_filter('wp_title', 'af_titledespacer');
to the functions file and that solved the problem.
Thanks again!