protected static function prepareTerms($post)
{
$taxonomies = get_object_taxonomies($post->post_type, 'objects');
$terms = [];
foreach ($taxonomies as $taxonomy) {
$objectTerms = get_the_terms($post->ID, $taxonomy->name);
if (is_wp_error($objectTerms)) {
continue;
}
if (!$objectTerms) {
$terms[$taxonomy->name] = [];
continue;
}
foreach ($objectTerms as $term) {
$allSlugs = [$term->slug];
//Add parent slug
if ($parent = get_term_by('id', $term->parent, $term->taxonomy)) {
$allSlugs[] = $parent->slug;
}
$terms[$term->taxonomy][] = ['term_id' => $term->term_id, 'slug' => $term->slug, 'name' => $term->name, 'parent' => $term->parent, 'all_slugs' => $allSlugs];
}
}
return $terms;
}