<?php
defined('_JEXEC') or die; // Joomla
$parent_tag_id=12345; // your tag id here
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
$tags_tree=JTable::getInstance('Tag', 'TagsTable')->getTree($parent_tag_id);
// Show children:
foreach($tags_tree as $tags_tree_id=>$tags_tree_item) {
echo 'DEBUG: ';
echo ' id:' . $tags_tree_item->id;
echo ' level:' . $tags_tree_item->level;
echo ' path:' . $tags_tree_item->path;
$link=TagsHelperRoute::getTagRoute($tags_tree_item->id . ':' . $tags_tree_item->path);
echo ' link: ' . JRoute::_( $link, true, 1);
echo '<br>';
}
Additonally, to get all parent tag ordered form root to current depth level:
<?php
defined('_JEXEC') or die; // Joomla
$tag_id=12345; // your tag id here
$parent_tags=JTable::getInstance('Tag', 'TagsTable')->getPath($tag_id);
// Show parents and self:
foreach($parent_tags as $parent_tags_id=>$parent_tags_item) {
echo 'DEBUG: ';
echo ' id:' . $parent_tags_item->id;
echo ' level:' . $parent_tags_item->level;
echo ' path:' . $parent_tags_item->path;
echo ' published:' . $parent_tags_item-->published;
echo '<br>';
}
Please note: you might need to check the published property, as you will get all tags, even the trashed ones. 1 is published, 0 is hidden, -2 is trashed, 2 is archived.
See https://api.joomla.org/cms-3/classes/Joomla.CMS.Router.Route.html also.