gpt4 book ai didi

wordpress - $wpdb 在另一个页面中不起作用

转载 作者:行者123 更新时间:2023-12-05 05:23:55 31 4
gpt4 key购买 nike

我创建了一个简单的插件,它在主页上工作,但是当我创建一个链接到用户去另一个页面查看信息时,它向我显示 fatal error :未捕获错误:调用成员函数 get_results()

我的代码是:

<?php

global $wpdb;
$results = $wpdb->get_results("SELECT * FROM wp_customers");
?>
<body>
<table>
<tr>
<th>‌ID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>

<?php foreach($results as $results){
?>
<tr>
<td>
<?php echo $results->id; ?>
</td>
<td>
<?php echo $results->name; ?>
</td>
<td>
<?php echo $results->family; ?>
</td>
<td>
<?php echo $results->numbers; ?>
</td>
<td>
<?php echo $results->tell; ?>
</td>
<?php }?>
</tr>
</table>

最佳答案

您需要检查您没有将数据库前缀设置为“wp_”以外的内容。

如果数据库中有 wp_ 前缀,则必须在自定义页面中包含 wp-load 文件。

require( '/path/to/wp-load.php' );

关于wordpress - $wpdb 在另一个页面中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36575854/

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