Compare node titles and do action?

Events happening in the community are now at Drupal community events on www.drupal.org.
not.used.922's picture

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

Ashford's picture

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

  1. Event: After saving new content
  2. Condition: Node has type - 'your content type name'
  3. Action: Execute Custom PHP code
    $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);
      }
    }

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: