For a Backdrop CMS site I'm currently working on, I needed to create a node programatically (i.e. via some PHP code, as opposed to the UI). Generally when I need to do something in Backdrop, I'll search for similar solutions in Drupal 7 and then migrate them over (Backdrop still has some catching up to do in the 'online help and tutorials' department; hence this blog post).
So I went looking for how to create nodes programatically in Drupal 7, and there were plently of results. The answer is basically to create an object or array of values (your 'node'), then run it through node_save()
. Unfortunately each answer had a different idea about exactly what values you should initially assign to your 'node'. Wanting a more bullet-proof solution, I kept looking and finally saw a suggestion someone made to check out the Devel Generate module. It creates nodes programatically, so it has the code to do just this. Since that module already exists in Backdrop, I had a look.
Devel Generate creates nodes by: