'SP Page builder AND operator

please help. I have the code from SP PAGE BUILDER. Currently, it displays articles with any tag. I need to modify it to display articles containing all selected tags. So the AND operator. Now works as an OR. I've been tormenting this for several hours. Please help.

// tags filter
    if (is_array($tagids) && count($tagids))
    {
        $tagId = implode(',', ArrayHelper::toInteger($tagids));

        if ($tagId)
        {
            $subQuery = $db->getQuery(true)
                ->select('DISTINCT content_item_id')
                ->from($db->quoteName('#__contentitem_tag_map'))
                ->where('tag_id IN (' . $tagId . ')')
                ->where('type_alias = ' . $db->quote('com_content.article'));

            $query->innerJoin('(' . (string) $subQuery . ') AS tagmap ON tagmap.content_item_id = a.id');
        }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source