Count pages with attribute (tag) assigned

Permalink
Hi,
how can I retrieve the number of pages that have an attribute (a tag) applied to? In previous version I used this function that in 8.10 seems not working.
thanks

public function pageUseCount($optID) {
      $db = Loader::db();
      $q = "select Pages.cID from Pages where cIsActive = 1";
      $r = $db->query($q);
      if ($r) {
         while ($row = $r->fetchRow()) {        
            $page = Page::getByID($row['cID']);
            if (gettype($page->getAttribute($this->attributeHandle)) == 'object') {
               foreach($page->getAttribute($this->attributeHandle) AS $v) {
                  if ($v->ID == $optID) $i[$v->ID][] = true;
               }
            }
         }
      }
      return count($i[$optID]);

 

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.