2

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.

  1. wp-config.php
  2. wp-load.php
  3. 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.

aynber
  • 22,380
  • 8
  • 50
  • 63
Jay Shukla
  • 5,794
  • 8
  • 33
  • 63

1 Answers1

2

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.

Technoh
  • 1,606
  • 15
  • 34