Skip to content

Instantly share code, notes, and snippets.

@tjsingleton
Created March 26, 2010 21:00
Show Gist options
  • Save tjsingleton/345388 to your computer and use it in GitHub Desktop.
Save tjsingleton/345388 to your computer and use it in GitHub Desktop.
<?php
$Members = new Pod('members');
$Members->findRecords($orderby = 'city ASC', 100);
// group members by city
$members_by_city = array();
while ($data = $Members->fetchRecord()) {
$city_name = $data["city"];
if(!$members_by_city[$city_name]) {
$members_by_city[$city_name] = array($data);
} else {
array_push($members_by_city[$city_name], $data);
}
}
// get the template for reuse
$tpl = 'member';
$result = pod_query("SELECT code FROM @wp_pod_templates WHERE name = '$tpl' LIMIT 1");
$row = mysql_fetch_assoc($result);
$code = $row['code'];
foreach ($members_by_city as $city => $members) {
echo "<br/><h3>".$city."</h3>";
// hack to use showTemplate
$Member = new Pod('members');
foreach($members as $member_data) {
$Member->data = $member_data;
$Member->id = true; # don't call fetchRecord again;
echo $Member->showTemplate("member", $code);
}
}
echo $Members->getPagination();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment