"UPDATE mytable SET column1 = value1, column2 = value2, ... WHERE status = 'pending'"; 

how can i write above query in magento2 ?

I try this.

$postData = $objectManager->create('vendor\module\Model\PostFactory');
        $arrayData = [ 
                        'status' =>'send'
 $sql = $postData->create()

1 Answer 1


Try this code

echo "<pre>";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$post = $objectManager->Create('\vendor\module\Model\ResourceModel\Post\Collection')->addFieldToFilter('status','pending');

foreach ($post as $key => $value) {
    $post_data = $objectManager->Create('\vendor\module\Model\Post')->load($value->getId());


if column name is create_data then it should be like setCreateData() and column name is status then it should be like setStatus().

I Hope This Helps You


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.