即使在“全局 $wpdb"之后 $wpdb 也是空的 [英] $wpdb is null even after 'global $wpdb
问题描述
我已经看到了几乎所有的链接,但我仍然无法解决我的问题.
我将 $wpdb 设为 null
.
我是这样检查的.我在 single.php 文件中这样做
echo "";print_r($wpdb);"
";
我检查了以下文件.全部加载完毕.
- wp-config.php
- wp-load.php
- wp-includes/wp-db.php
请帮帮我.
编辑
我想像这样执行自定义查询.
$entries = $wpdb->get_results( $wpdb->prepare( "SELECT forms.form_title,entries.*FROM wp_visual_form_builder_forms AS 表单INNER JOIN wp_visual_form_builder_entries AS 条目 ON entry.form_id = forms.form_id" ) );
这不起作用.
如果您阅读了文档,你会注意到这段话:
始终使用全局 $wpdb 变量.(记住在任何自定义函数中使用 $wpdb 之前将其全球化.)
这不是很清楚,但我认为这意味着您不能在函数之外使用 $wpdb
.我建议您在主题的 functions.php
文件中创建一个函数,并从 single.php 文件中调用该函数.
I have seen almost all links but still I am unable to solve my problem.
I am getting $wpdb as null
.
I am checking it like this. I am doing this in single.php file
echo "<pre>";print_r($wpdb);"</pre>";
I have checked about following files. That all are loaded.
- wp-config.php
- wp-load.php
- wp-includes/wp-db.php
Please help me.
EDIT
I want to execute custom query like this.
$entries = $wpdb->get_results( $wpdb->prepare( "SELECT forms.form_title, entries. *
FROM wp_visual_form_builder_forms AS forms
INNER JOIN wp_visual_form_builder_entries AS entries ON entries.form_id = forms.form_id" ) );
this is not working.
If you read the documentation, you will notice this passage:
Always use the global $wpdb variable. (Remember to globalize $wpdb before using it in any custom functions.)
It's not very clear but I think that means you cannot use $wpdb
outside of a function. What I recommend you do is create a function in your theme's functions.php
file, and call that function from the single.php file.
这篇关于即使在“全局 $wpdb"之后 $wpdb 也是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!