Posted by not.used.922 on July 9, 2009 at 5:11pm
Is there a way to unpublish a node if a new node is created with the same title? I'm feeling a little daft trying to figure it out from reading here, the issues queue, and the documentation. (Let me know if I need to move this to an issue, BTW.)
Comments
re: Rule to unpublish the duplicate title
You asked your question back in July. Hopefully you found n answer by now. If not, try this Triggered Rule on your demo site. Don't use it on your live site until you have thoroughly tested it. I'm new at this stuff myself and may have gotten something wrong. ---Ashford
$current_nid = $node->nid;
$current_title= $node->title;
// Find all the node id's where the title=your title
$results = db_query("SELECT nid FROM {node_revisions} WHERE title = '%s' ", $current_title);
while ($obj = db_fetch_object($results)) {
// Did we find a nid that is not the current one?
if ($obj->nid != $current_nid) {
// node_delete($obj->nid);
//
// load the duplicate node
$duplicate = node_load($obj->nid);
// update the published status
$duplicate->status = 0;
// save the node
$node_submit($duplicate);
$node_save($duplicate);
}
}