Display PODS of a specific category
Here is a small PHP snippet on how to display PODS of a specific category inside your WordPress page.
<?php
$categ = "";
if (isset($_GET['categ']))
$categ = trim($_GET['categ']);
// select only the active taxonomies
$query = "select t.name, t.slug, t.term_id, tt.parent from wp_terms as t "
. "inner join wp_term_taxonomy as tt on t.term_id = tt.term_id and tt.taxonomy = 'area' "
. "inner join wp_term_relationships as tr on tr.term_taxonomy_id = tt.term_taxonomy_id "
. "inner join wp_posts as tp on tp.ID = tr.object_id "
. "group by t.slug "
. "order by t.term_id, tt.parent";
$groups = pods_query($query);
if (!empty($groups)) {
$children = array_filter($groups, function ($itm) { return ($itm->parent > 0); });
foreach ($groups as $item) {
if ($item->parent == 0) {
$is_selected = $categ == $item->slug ? " data-default-selected=''" : "";
echo "<a class='dropdown-item' data-value='".$item->slug."' data-level='1'".$is_selected." href='#' id='".$item->term_id."'>".html_entity_decode($item->name)."</a>";
}
}
}
?>
The idea is to build a list of available categories from a specific PODS list and to mark the given category ($categ) as selected.