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)

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);
  • That won't clear the relevant caches... – Clive Feb 17 '15 at 14:54
  • Clive, I updated my code to clear the relevant caches, good call! – Fons Vandamme Feb 17 '15 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 Feb 17 '15 at 15:02
  • good call (again), i'll update the code – Fons Vandamme Feb 17 '15 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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