0

I want to create one or more new tags, add them to Joomla tag table and associate them with an existing article with a given ID.

e.g article ID is 28 and tags are named "Firsttag", "secondtag". My PHP script is not working:

defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Form\Form;
use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Helper\TagsHelper;


$content = JTable::getInstance("Content", 'JTable', array());
$content->load($id) = 28;

$title = "Tag Title";
$i = new JHelperTags;
$i->createTagsFromField(array("#new#$title"));


$i = new JHelperTags();
$i->tagItem($content->id, $content, array("Firsttag", "secondtag"));
JHelperTags::addTags(array("tag1", "tag2"), $content);

$i  ->store();
1
  • Thanks for join our community. Please take our tour. Please be more specific about "My PHP script is not working" -- are there any errors? is there no output in the source code? are you seeing output that is unintended? Have you var_dump()ed the variables that you are populating to see if they contain the expected values? Offering any/all relevant diagnostic clues can help volunteers to better understand your issue and provide better answers faster. – mickmackusa Nov 15 '20 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.