1

I sometimes have uses cases where I want to be able to change the type of a node. There is a nodetype module that comes with a big disclaimer: "only use if you know what you are doing".

Of course I would lose any fields if they have a different name with the other type. What else could go wrong?

Would it be save to use node_load(), modify the type and then use node_save()?

  • 2
    that's actually pretty much all the nodetype module does, it just hooks into nodeapi and changes the type on save. – Jimajamma Feb 21 '12 at 17:15
2

I've changed the content type of nodes directly in the database plenty of times and the only thing I've had to deal with is orphaned field data for nodes.

I think that this orphaned data might cause some false-positive results for certain query types (EntityFieldQuery springs to mind) but I can't be absolutely sure.

Instead of risk this I've always written a small script to go through the field tables in question and clear up any stagnant data after I've made the content type change.

I don't think you'll encounter any errors using node_load() and node_save() as you suggest; it would probably be wise to clear Drupal's cache once you've made the change in case anything needs to be updated there.

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.