Creating a wordpress plugin and need this plugin to automatically add posts to wordpress when it installs. What is the better solution to do that?
Asked
Active
Viewed 42 times
1 Answers
0
You should use the register_activation_hook
to carry out any custom functions (like adding posts) after the plugin is initialised.
function myplugin_activate() {
// Add your posts here...
}
register_activation_hook( __FILE__, 'myplugin_activate' );
That way, once the plugin is installed, and activated, myplugin_activate()
will fire, and carry out any logic you put there.
See: https://codex.wordpress.org/Function_Reference/register_activation_hook for more information.

prettyfly
- 2,962
- 1
- 25
- 27
-
Thanks! Exactly what I've been looking for. And is this [link](https://gist.githubusercontent.com/imelgrat/bbc26d3d0724d29a8e0f7da5832e7767/raw/416c7dec3d41a846d64739e98f270ce40cf26d4e/bulk-post-create.php) a suitable way for adding posts? – Yaroslav Karaninkiy Nov 20 '17 at 13:40
-
Yeah, that should be fine for pulling data from another source and inserting them as posts in Wordpress. – prettyfly Nov 20 '17 at 13:49