How to add tags using PHP

Permalink
Hi

The docs, as usual have come up short, how can I add tags to a page object using PHP?

Thanks

yolk
 
yolk replied on at Permalink Reply
yolk
I have now found

$newPage->addAttribute("tags", "golf");
$newPage->addAttribute("tags", "news");
$newPage->addAttribute("tags", "walks");


But this only adds one tag and not three. Looking at the page properties there is just "walks" and not the other two, it is like the first two are ignored and overwritten by the third?

Any ideas?

Thanks
Mainio replied on at Permalink Best Answer Reply
Mainio
Not sure but best guess:
$newPage->setAttribute('tags', array('golf', 'news', 'walks'));


So, if you want to add new ones to existing:
$old = $newPage->getAttribute('tags');
$newPage->setAttribute('tags', array_merge($old, array('new', 'new2')));


The SelectAttributeTypeOption also has a static method add() but I guess the method above is easier (if it works).
yolk replied on at Permalink Reply
yolk
Hi

Thanks! I have just found that too here

http://www.concrete5.org/community/forums/customizing_c5/cannot-add...

Thanks again