wp_insert_post仅一次用于自定义帖子类型



我已经创建了一个插件,启用自定义帖子类型,我已经插入了一些默认值与wp_insert_post这个帖子类型。

wp_insert_post( array(
    'ID' => '3',
    'post_status' => 'publish',
    'post_type' => 'exhibitor',
    'post_title' => 'Title',
    'post_content' => 'Description...'
) );

问题是每次页面刷新时我的值都被重新插入。我不能编辑或删除它们。

当我的插件被激活时,我如何让Wordpress只更新自定义帖子类型?每次我刷新一个页面,帖子就会再次发布。所以我不能编辑或删除帖子。

认为,

在你的插件中使用register_activation_hook,这是插件激活时运行的插件函数

register_activation_hook(__FILE__, 'newplugin_install');
function newplugin_install() {
wp_insert_post( array(
    'ID' => '3',
    'post_status' => 'publish',
    'post_type' => 'exhibitor',
    'post_title' => 'Title',
    'post_content' => 'Description...'
) );
}

希望这对你有用;)

最新更新