gpt4 book ai didi

php - mytheme/update.php 中的 wordpress 查询

转载 作者:行者123 更新时间:2023-11-29 00:25:24 24 4
gpt4 key购买 nike

在我的 wordpress 主题中,我创建了一个名为 update.php 的文件。我可以通过以下方式访问此 URL http://mydomain.com/wp-content/themes/mytheme/update.php

这里是update.php里面的代码

global $wpdb;
// do some more stuff here
$wpdb->update( 'twitter_followers', array('count' => $followers), array('id' => '1') );
echo 'done';

当我转到此页面时出现此错误。

PHP Fatal error: Call to a member function update() on a non-object in /var/www/vhosts/mydomain.com/subdomains/mytheme/httpdocs/wp-content/themes/mytheme/update.php on line 34 

关于如何解决这个问题的任何想法?

另请注意,我确实在我的数据库中创建了 twitter_followers 表。

最佳答案

问题是您还没有 $wpdb,因为您的 update.php 不是 wordpress 的一部分。当您转到 update.php 时,永远不会加载 wordpress,因此您会收到非对象错误。尝试将此行添加到 update.php 文件的顶部,显然更改路径:

require_once("/path/to/wordpress/wp-load.php");

在正常安装中路径可能看起来像这样:

require_once("../../../../wp-load.php");

关于php - mytheme/update.php 中的 wordpress 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19169244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com