/** * Create a new Term object. * * @param int|\WP_Term $term Term ID or term object * @param \Tev\Taxonomy\Model\Taxonomy $taxonomy Term taxonomy * @return \Tev\Term\Model\Term Term object * * @throws \Exception If term could not be created from given data */ public function create($term, Taxonomy $taxonomy) { if (!$term instanceof WP_Term) { $term = get_term($term, $taxonomy->getName()); } if ($term && !$term instanceof WP_Error) { return new Term($term, $taxonomy, $this); } else { throw new Exception('Term not found'); } }
/** * Return array of direct child terms of this term. * * @return \Tev\Term\Model\Term[] */ 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; }