Code running in one theme but not the other
Themes are highly cached. That's a reason why you should avoid logic in them if only you can. And if you have to, put it in template.php, not .tpl files. Probable reason of query not executed is that template got cached and Drupal sees no reason to evaluate files again. You could force it to, probably, but it would be a huge performance killer.

Move your queries to contrib module, and query-based logic to template.php and you'll be good.