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?

->condition('nid', $nids, 'IN')
->fields(['status' => NodeInterface::NOT_PUBLISHED])
  • It could be the data is still cached. Executing a query on the database isn't going to clear the cache. – kiamlaluno Nov 8 '19 at 13:51
  • Yeah try with something like this instead drupal.stackexchange.com/questions/234504/… – Leigh Nov 8 '19 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 '19 at 13:59

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.