Skip to content

Instantly share code, notes, and snippets.

@b2z
Last active January 17, 2020 19:17
Show Gist options
  • Save b2z/eb11c3fc790784b51e87986790cfefc2 to your computer and use it in GitHub Desktop.
Save b2z/eb11c3fc790784b51e87986790cfefc2 to your computer and use it in GitHub Desktop.
Get Joomla article SEF url by article alias
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$alias = 'title';
$query->select($query->quoteName(array('id', 'catid')))
->from($query->quoteName('#__content'))
->where($query->quoteName('alias') . ' = ' . $query->quote($alias));
$item = $db->setQuery($query)
->loadObject();
if (!empty($item))
{
JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->id . ':' . $alias, $item->catid));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment