Skip to content

Instantly share code, notes, and snippets.

@morad7
Last active October 21, 2015 17:11
Show Gist options
  • Save morad7/4198246e2487d7e64850 to your computer and use it in GitHub Desktop.
Save morad7/4198246e2487d7e64850 to your computer and use it in GitHub Desktop.
Auto increment nodes titles
// for auto_nodetitle module
<?php
$count = db_select('node')->fields('node')->condition('type', $node->type)->execute()->rowCount();
$id = $count+1;
$title = 'stg'.$id;
$nodes = db_select('node', 'a')->fields('a', array('title'))->condition('type',$node->type)->execute();
foreach ($nodes as $nod) {
if ($title == $nod->title) {
$id = $id + 1;
$title = 'stg'.$id;
}
}
print $title;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment