我正在尝试创建一个插件来更新 Wordpress 数据库表中的变量。我的管理页面上有以下内容
<button type="button" onclick='myfunction()'>Update</button>
<script>
function myfunction(){
jQuery.get('<?php echo $plugin_url = plugins_url('plugin-name'); ?>/scan-update-table.php');
return false;
};
</script>
scan-update-table.php 看起来像这样:
global $wpdb;
$wpdb->update('wp_scan_featured', array('post_ID'=>44), array('role'=>'lead_article'));
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
当我按下按钮时没有任何反应,但是当我打开 scan-update-table.php 文件时出现错误:致命错误:调用非对象上的成员函数 update()