0

I'm updating a node's status to unpublished and the status in node_field_data is changed from 1 to 0 but in the content view, status is published and when editing the node, the publish checkbox is still checked.

What am I missing?

Drupal::database()->update('node_field_data')
->condition('nid', $nids, 'IN')
->fields(['status' => NodeInterface::NOT_PUBLISHED])
->execute();
3
  • It could be the data is still cached. Executing a query on the database isn't going to clear the cache.
    – apaderno
    Nov 8, 2019 at 13:51
  • Yeah try with something like this instead drupal.stackexchange.com/questions/234504/…
    – Leigh
    Nov 8, 2019 at 13:52
  • A better way to do this in Drupal 8 is like this, $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids); foreach ($nodes as $node) { $node->setPublished(FALSE); $node->save(); }
    – user72672
    Nov 8, 2019 at 13:59

0

Your Answer

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

Browse other questions tagged or ask your own question.