I developed a theme for my client. Theme have predefined posts, pages and sliders etc. when some one activate the theme, theme does the following steps on theme activation action hook. 1:- Empty the current WordPress database to avoid any duplicate data entry issue. 2:- Inserts predefined data in the WordPress core tables and creates some other required custom tables with data. Everything is working fine accept one issue and that is my theme removes all the previous data in the database. so that client lost his all previous data. i need any idea or help to tackle this issue. User just want to add new theme using theme zip file and all the posts and pages each and everything should be done automatically. Any help or idea will be highly appreciated.

1 Answer 1


Never change content without the user's specific manual request, and never ever delete anything from the DB that you haven't created.

So the only question left is how to create you sample content. The cleanest way is to provide an exported sample that can be imported into WP. The only problem with this approach is that it requires the installation of the wordpress importer plugin. The other possible approach is to write a code that will generate the sample content, but this also needs to be triggered by a manual action by the user.

If your user is not very bright (as most users are ;) ) you can show a short message about the existence of the option to import/generate a sample after theme's activation.

  • Appreciate your response. But i have to do this in same manners. I tried generating xml using WordPress exporter plugin and then import it using the WordPress importer plugin but client rejected it as he does not want to do such kind of activity, after that i wrote a function for importing data in the database on the the theme activation hook. So any idea?
    – jojo
    Commented Aug 11, 2014 at 12:07
  • I am deleting the user data only because of the primary key duplication constraint. Let say i have a post with the id of 3 in sample data and in the users database the id 3 is already occupied. so what should i do in that case?
    – jojo
    Commented Aug 11, 2014 at 12:13
  • Why should you care what is the ID of the post? Commented Aug 11, 2014 at 12:24
  • because i have to insert the sample data in the database with the theme activation. And if the post id is already filled with some other post then it shows the duplication error. and if let say in any case i managed to inserted it on the same id then i lost the old data.... same issue again
    – jojo
    Commented Aug 11, 2014 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.