When using getCriteria() along with buildElementsQuery() raw html gets displayed by the template
$query-&gt;queryAll() returns raw arrays of data from the database, this is why you're needing to prepend field_ to each attribute, to get the column name.

You need to populate some EntryModels before you can use them properly in the templates, with something along the lines of:

$query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);

// modify the query here

$results = $query-&gt;queryAll();

return EntryModel::populateModels($results);