Timber\Post::terms PHP Метод

terms() публичный Метод

Get the terms associated with the post This goes across all taxonomies by default
public terms ( string | array $tax = '', boolean $merge = true, $TermClass = '' ) : array
$tax string | array What taxonom(y|ies) to pull from. Defaults to all registered taxonomies for the post type. You can use custom ones, or built-in WordPress taxonomies (category, tag). Timber plays nice and figures out that tag/tags/post_tag are all the same (and categories/category), for custom taxonomies you're on your own.
$merge boolean Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
Результат array
    public function terms($tax = '', $merge = true, $TermClass = '')
    {
        $taxonomies = array();
        $TermClass = $TermClass ?: $this->TermClass;
        if (is_string($merge) && class_exists($merge)) {
            $TermClass = $merge;
        }
        if (is_array($tax)) {
            $taxonomies = $tax;
        }
        if (is_string($tax)) {
            if (in_array($tax, array('all', 'any', ''))) {
                $taxonomies = get_object_taxonomies($this->post_type);
            } else {
                $taxonomies = array($tax);
            }
        }
        $term_class_objects = array();
        foreach ($taxonomies as $taxonomy) {
            if (in_array($taxonomy, array('tag', 'tags'))) {
                $taxonomy = 'post_tag';
            }
            if ($taxonomy == 'categories') {
                $taxonomy = 'category';
            }
            $terms = wp_get_post_terms($this->ID, $taxonomy);
            if (is_wp_error($terms)) {
                /* @var $terms WP_Error */
                Helper::error_log("Error retrieving terms for taxonomy '{$taxonomy}' on a post in timber-post.php");
                Helper::error_log('tax = ' . print_r($tax, true));
                Helper::error_log('WP_Error: ' . $terms->get_error_message());
                return $term_class_objects;
            }
            // map over array of wordpress terms, and transform them into instances of the TermClass
            $terms = array_map(function ($term) use($TermClass, $taxonomy) {
                return call_user_func(array($TermClass, 'from'), $term->term_id, $taxonomy);
            }, $terms);
            if ($merge && is_array($terms)) {
                $term_class_objects = array_merge($term_class_objects, $terms);
            } else {
                if (count($terms)) {
                    $term_class_objects[$taxonomy] = $terms;
                }
            }
        }
        return $term_class_objects;
    }