In general, the WebTemplate database is queried though the use of the WebTemplate::query function. The query function takes in a single argument which defines the Node Type to seach for, the Path in the tree to search, Criteria which the results must match.
An Example: print the first name of all contacts with a first name beginning with J:
// an array to store the results in
$results = Array();
// build and run the query
$query = Array();
$query["Node Type"] = "Contact";
$query["Path"] = "/Contacts/*";
$query["Criteria"] = "`First Name` LIKE 'J%'";
$query["Results Array"] = &$results;
$GLOBALS["WT"]->query($query);
// loop through the results
foreach($results as $result) {
print $result["First Name"];
}