Back to TagsHelper class

Method unTagItem

public bool
unTagItem
(mixed $contentId, \Joomla\CMS\Table\TableInterface $table, mixed $tags = array())
Method to untag an item
Parameters
  • int $contentId ID of the content item being untagged
  • \Joomla\CMS\Table\TableInterface $table Table object being untagged
  • array $tags Array of tags to be untagged. Use an empty array to untag all existing tags.
Returns
  • bool true on success, otherwise false.
Since
  • 3.1
Class: TagsHelper
Project: Joomla

Method unTagItem - Source code

/**
 * Method to untag an item
 *
 * @param   integer         $contentId  ID of the content item being untagged
 * @param   TableInterface  $table      Table object being untagged
 * @param   array           $tags       Array of tags to be untagged. Use an empty array to untag all existing tags.
 *
 * @return  boolean  true on success, otherwise false.
 *
 * @since   3.1
 */
public function unTagItem($contentId, TableInterface $table, $tags = array())
{
    $key = $table->getKeyName();
    $id = (int) $table->{$key};
    $db = Factory::getDbo();
    $query = $db->getQuery(true)->delete($db->quoteName('#__contentitem_tag_map'))->where([$db->quoteName('type_alias') . ' = :type', $db->quoteName('content_item_id') . ' = :id'])->bind(':type', $this->typeAlias)->bind(':id', $id, ParameterType::INTEGER);
    if (\is_array($tags) && \count($tags) > 0) {
        $tags = ArrayHelper::toInteger($tags);
        $query->whereIn($db->quoteName('tag_id'), $tags);
    }
    $db->setQuery($query);
    return (bool) $db->execute();
}