如何在wordpress中使用自己的插件添加帖子

How to add posts using own plugin in wordpress

正在创建一个 wordpress 插件并需要此插件在安装时自动将帖子添加到 wordpress。什么是更好的解决方案?

您应该在插件初始化后使用 register_activation_hook 执行任何自定义功能(如添加帖子)。

 function myplugin_activate() {

     // Add your posts here...
 }
 register_activation_hook( __FILE__, 'myplugin_activate' );

这样,一旦安装并激活插件,myplugin_activate() 就会启动,并执行您放置在那里的任何逻辑。

有关详细信息,请参阅:https://codex.wordpress.org/Function_Reference/register_activation_hook