0

To unpublish a node, I set status=0 and call node_save(). Unfortunately, this invokes the Geocoder module and it sends a request to the Google API for a geocode that I already have. There is apparently no way to turn this off.

I am looking for an alternative to node_save() that does not trigger this behavior or any other hooks, for that matter.

(btw, for fields I am achieving this with field_attach_update, but to unpublish I need to update the node itself)

1 Answer 1

4

If you have an array of nids you could just run this piece of code

example will unpublish the nodes with nid 1,2,3:

$nids = array(1, 2 ,3);

foreach($nids as $nid) {
    db_query("UPDATE {node} SET `status` = '0' WHERE `nid` =:nid ;"
,array(':nid'=> $nid));
}

entity_get_controller('node')->resetCache($nids);
4
  • That won't clear the relevant caches...
    – Clive
    Commented Feb 17, 2015 at 14:54
  • Clive, I updated my code to clear the relevant caches, good call! Commented Feb 17, 2015 at 14:56
  • Nice :) For a performance gain, you could take it out of the loop and run entity_get_controller('node')->resetCache($nids); directly
    – Clive
    Commented Feb 17, 2015 at 15:02
  • good call (again), i'll update the code Commented Feb 17, 2015 at 15:04

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.