下面的代码包含在插件文件中。它只是试图对wp数据库执行更新查询。但是,它会生成一个致命错误。
Fatal error: Cannot redeclare ce3_cleanup()
我是否需要加载配置文件才能访问$wpdb->查询?
function ce3_cleanup()
{
$wpdb->query("update wp_postmeta set meta_key=replace(meta_key,\'cb2_customHeader\',\'_cb2_customHeader\') where meta_key like \'cb2_customHeader\'");
$wpdb->query("update wp_postmeta set meta_key=replace(meta_key,\'cb2_customTitle\',\'_cb2_customTitle\') where meta_key like \'cb2_customTitle\'");
}
register_activation_hook(__FILE__, \'ce3_cleanup\');
?>
最合适的回答,由SO网友:sorich87 整理而成
编写该函数的建议方法是:
function ce3_cleanup() {
global $wpdb;
$wpdb->query( "update $wpdb->postmeta set meta_key=replace(meta_key,\'cb2_customHeader\',\'_cb2_customHeader\') where meta_key like \'cb2_customHeader\'" );
$wpdb->query( "update $wpdb->postmeta set meta_key=replace(meta_key,\'cb2_customTitle\',\'_cb2_customTitle\') where meta_key like \'cb2_customTitle\'" );
}
register_activation_hook( __FILE__, \'ce3_cleanup\' );