TransWikia.com

Craft 2: edit a value in a matrix field

Craft CMS Asked on June 12, 2021

This should be fairly easy but I can’t figure it out:

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'news';
$entries = $criteria->first(); // a simple "Single"
$videos = $entries->video; //the matrix
foreach ($videos as $item) {
    if($item->video[0]->id == $video) {
        $item->count = $item->count++;
        craft()->entries->saveEntry($entries);
    }
}

This was my original approach which throws Property "CraftMatrixBlockModel.count" is not defined. (even though simply echoing $item->count does work.)
I subsequently tried 42 combinations of setAttribute() and the like up to the point where it didn’t throw an error but so far my value was never updated. count is a simple Number field in a Matrix.
Thanks

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP