Gets the term counts for each supplied taxonomy.

@param array $taxonomies Taxonomies to fetch counts for.
@return array Associative array of term counts keyed by taxonomy.
169355
protected function get_counts( $taxonomies ) {
		global $wpdb;

		if ( count( $taxonomies ) <= 0 ) {
			return [];
		}

		$query = $wpdb->prepare(
			"SELECT `taxonomy`, COUNT(*) AS `count`
			FROM $wpdb->term_taxonomy
			WHERE `taxonomy` IN (" . implode( ',', array_fill( 0, count( $taxonomies ), '%s' ) ) . ')
			GROUP BY `taxonomy`',
			$taxonomies
		);
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $query is already prepared above.
		$counts = $wpdb->get_results( $query );

		// Make sure there's a count for every item.
		$counts = array_merge(
			array_fill_keys( $taxonomies, 0 ),
			wp_list_pluck( $counts, 'count', 'taxonomy' )
		);

		return $counts;
	}
40045
def term_counts(self):

        

        counts = OrderedDict()
        for term in self.terms:
            counts[term] = len(self.terms[term])

        return utils.sort_dict(counts)
988982
public function count(array $locales = null,  array $filters = null)
    {
        $this->loadCustomHydrator();

        $builder = $this->createQueryBuilder('tu')
            ->select('COUNT(DISTINCT tu.id) AS number');

        $this->addTransUnitFilters($builder, $filters);
        $this->addTranslationFilter($builder, $locales, $filters);

        return (int) $builder->getQuery()->getResult(Query::HYDRATE_SINGLE_SCALAR);
    }
702693
public static function getCategoriesCount($filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCount('/categories/count' . $filter->toQuery());
    }
1263544
public function dashboardTaxonomies()
    {
        $taxonomies = get_taxonomies($args, $output, $operator);

        foreach ($taxonomies as $taxonomy) {
            $num_terms  = wp_count_terms($taxonomy->name);
            $num = number_format_i18n($num_terms);
            $text = _n($taxonomy->labels->singular_name, $taxonomy->labels->name, intval($num_terms));

            if (current_user_can('manage_categories')) {
                $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num";
                $text = "$text</a>";
            }

            echo '<li class="post-count">' . $num . ' ' . $text . '</li>';
        }
    }
298618
public function getAll(array $filters = null)
    {
        $search = $this->repository->createSearch();
        $search->addQuery(new MatchAllQuery());
        $search->setScroll('2m');

        if ($filters) {
            foreach ($filters as $field => $value) {
                $search->addQuery(new TermsQuery($field, $value));
            }
        }

        return $this->repository->findDocuments($search);
    }
337896
public function get_custom_taxonomies(){
    global $wpdb;

    $query = sprintf('SELECT * FROM %s ORDER BY id',MF_TABLE_CUSTOM_TAXONOMY);
    $custom_taxonomies = $wpdb->get_results( $query, ARRAY_A );
    return $custom_taxonomies;
  }
1179468
protected static function fetch_concepts(array $glossaries) {
        global $DB;

        $glossarylist = implode(',', $glossaries);

        $sql = "SELECT id, glossaryid, concept, casesensitive, 0 AS category, fullmatch
                  FROM {glossary_entries}
                 WHERE glossaryid IN ($glossarylist) AND usedynalink = 1 AND approved = 1

                 UNION

                SELECT id, glossaryid, name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch
                  FROM {glossary_categories}
                 WHERE glossaryid IN ($glossarylist) AND usedynalink = 1

                UNION

                SELECT ge.id, ge.glossaryid, ga.alias AS concept, ge.casesensitive, 0 AS category, ge.fullmatch
                  FROM {glossary_alias} ga
                  JOIN {glossary_entries} ge ON (ga.entryid = ge.id)
                 WHERE ge.glossaryid IN ($glossarylist) AND ge.usedynalink = 1 AND ge.approved = 1";

        $concepts = array();
        $rs = $DB->get_recordset_sql($sql);
        foreach ($rs as $concept) {
            $currentconcept = trim(strip_tags($concept->concept));

            // Concept must be HTML-escaped, so do the same as format_string to turn ampersands into &amp;.
            $currentconcept = replace_ampersands_not_followed_by_entity($currentconcept);

            if (empty($currentconcept)) {
                continue;
            }

            // Rule out any small integers, see MDL-1446.
            if (is_number($currentconcept) and $currentconcept < 1000) {
                continue;
            }

            $concept->concept = $currentconcept;

            $concepts[$concept->glossaryid][] = $concept;
        }
        $rs->close();

        return $concepts;
    }
76112
protected function getEagerModelKeys(array $models)
    {
        $keys = array();

        /**
         * First we need to gather all of the keys from the parent models so we know what
         * to query for via the eager loading query. We will add them to an array then
         * execute a "where in" statement to gather up all of those related records.
         */
        foreach ($models as $model)
        {
            // In the case of fetching nested relations, we will get an array
            // with the first key being the model we need, and the other being
            // the related model so we'll just take the first model out of the array.
            if (is_array($model)) $model = reset($model);

            if ( ! is_null($value = $model->{$this->ownerKey}))
            {
                $keys[] = $value;
            }
        }

        /**
         * If there are no keys that were not null we will just return an empty array in
         * it so the query doesn't fail, but will not return any results, which should
         * be what this developer is expecting in a case where this happens to them.
         */
        if (count($keys) == 0)
        {
            return array();
        }

        return array_values(array_unique($keys));
    }
444704
public function getList()
    {
        if ($this->modelClass === TaxonomyTerm::class) {
            $list = parent::getList();
            return $list->filter('ParentID', '0');
        }
        return parent::getList();
    }
185673
protected function getEagerModelKeys(array $models)
    {
        $keys = [];

        // First we need to gather all of the keys from the parent models so we know what
        // to query for via the eager loading query. We will add them to an array then
        // execute a "where in" statement to gather up all of those related records.
        foreach ($models as $model) {
            if (is_array($this->foreignKey)) { //Check for multi-columns relationship
                $keys[] = array_map(function ($k) use ($model) {
                    return $model->{$k};
                }, $this->foreignKey);
            } else {
                if (! is_null($value = $model->{$this->foreignKey})) {
                    $keys[] = $value;
                }
            }
        }

        // If there are no keys that were not null we will just return an array with either
        // null or 0 in (depending on if incrementing keys are in use) so the query wont
        // fail plus returns zero results, which should be what the developer expects.
        if (count($keys) === 0) {
            return [$this->relationHasIncrementingId() ? 0 : null];
        }

        sort($keys);

        return array_values(array_unique($keys, SORT_REGULAR));
    }
1191399
protected function parseTaxonomy(array $taxonomies = null)
    {
        $taxonomies = $taxonomies ?: $this->parseConfigYaml('taxonomy.yml');
        $slugify = Slugify::create();

        foreach ($taxonomies as $key => $taxonomy) {
            if (!isset($taxonomy['name'])) {
                $taxonomy['name'] = ucwords(str_replace('-', ' ', Common\Str::humanize($taxonomy['slug'])));
            }
            if (!isset($taxonomy['singular_name'])) {
                if (isset($taxonomy['singular_slug'])) {
                    $taxonomy['singular_name'] = ucwords(str_replace('-', ' ', Common\Str::humanize($taxonomy['singular_slug'])));
                } else {
                    $taxonomy['singular_name'] = ucwords(str_replace('-', ' ', Common\Str::humanize($taxonomy['slug'])));
                }
            }
            if (!isset($taxonomy['slug'])) {
                $taxonomy['slug'] = $slugify->slugify($taxonomy['name']);
            }
            if (!isset($taxonomy['singular_slug'])) {
                $taxonomy['singular_slug'] = $slugify->slugify($taxonomy['singular_name']);
            }
            if (!isset($taxonomy['has_sortorder'])) {
                $taxonomy['has_sortorder'] = false;
            }
            if (!isset($taxonomy['allow_spaces'])) {
                $taxonomy['allow_spaces'] = false;
            }

            // Make sure the options are $key => $value pairs, and not have implied integers for keys.
            if (!empty($taxonomy['options']) && is_array($taxonomy['options'])) {
                $options = [];
                foreach ($taxonomy['options'] as $optionKey => $optionValue) {
                    if (is_numeric($optionKey)) {
                        $optionKey = $optionValue;
                    }
                    $optionKey = $slugify->slugify($optionKey);
                    $options[$optionKey] = $optionValue;
                }
                $taxonomy['options'] = $options;
            }

            if (!isset($taxonomy['behaves_like'])) {
                $taxonomy['behaves_like'] = 'tags';
            }
            // If taxonomy is like tags, set 'tagcloud' to true by default.
            if (($taxonomy['behaves_like'] === 'tags') && (!isset($taxonomy['tagcloud']))) {
                $taxonomy['tagcloud'] = true;
            } else {
                $taxonomy += ['tagcloud' => false];
            }

            $taxonomies[$key] = $taxonomy;
        }

        return $taxonomies;
    }
127279
public function getTagCounts(array $tagTokens): array
    {
        $tagCounts = [];

        foreach ($tagTokens as $tagToken) {
            $tagName = $tagToken['content'];

            if (!array_key_exists($tagName, $tagCounts)) {
                $tagCounts[$tagName] = 0;
            }

            ++$tagCounts[$tagName];
        }

        return $tagCounts;
    }
252125
public function getTermsByType($type)
    {
        $terms = new ArrayCollection();
        $taxonomies = $this->getTaxonomiesByType($type);

        /* @var TermTaxonomy $taxonomy */
        if ($taxonomies !== null) {
            foreach ($taxonomies as $taxonomy) {
                $terms[] = $taxonomy->getTerm();
            }
        }

        return ($terms->count() == 0) ? null : $terms;
    }
72797
public function getChildren()
    {
        $children = array();

        $wpTerms = get_terms($this->taxonomy->getName(), array(
            'hide_empty' => false,
            'parent'     => (int) $this->getId()
        ));

        foreach ($wpTerms as $termData) {
            $children[] = $this->termFactory->create($termData, $this->taxonomy);
        }

        return $children;
    }
259979
public static function getSchemasByNamespaces(array $namespaces)
    {
        $schemas = [];

        /** @var SchemaDescriptor $schema */
        foreach (self::$schemasByCurie as $schema) {
            if (in_array($schema->getId()->getNamespace(), $namespaces)) {
                $schemas[] = $schema;
            }
        }

        return $schemas;
    }
918362
public function countSoft($conditions = null, $values = [])
    {
        $res = $this->executeQuerySoft('COUNT(' . $this->key . ') AS num', $conditions, $values)
            ->fetch();
        return (isset($res->num) ? (int)$res->num : 0);
    }