WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a custom plugin for my WordPress site.

I made a php file called "checkrank" that obtains data from a custom table named "cranking".

$uid = $GET['id']; 

function checkExists($id){
    global $wpdb;
    $table_name = $wpdb->prefix . 'cranking';
    $exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d" ) );

    $error = $wpdb->print_error();

    if(count($exists) > 0){
       echo 'Exists!';
    } else {
       echo 'Does not exist!';

 return $error;


The code is just to check whether the cranking table has the user with the provided ID.

The problem is, whenever i run this php file, i get this error :

PHP Fatal error: Call to a member function get_row() on a non-object

Where am I at fault here?
I think $wbdp is not initiated.

share|improve this question
What do you mean by "whenever i run this php file"? Earlier, you mention that you are "building a custom plugin". Is this a plugin or a standalone file? – Johannes Pille Jul 27 '13 at 10:23
Hi,what i meant by running is going to the url (mysite.com/wp-content/plugins/myplugin/checkrank.php?id=1 – edward Jul 27 '13 at 10:25
this is a php file inside my plugin. – edward Jul 27 '13 at 10:26
up vote 1 down vote accepted

In a comment you clarify:

what i meant by running is going to the url

In that case, you are running a standalone file.

Yes, one that resides inside WordPress' plugins folder, but you don't access it in the context of WordPress (i.e. from within it). Here, none of the WordPress core functions/methods/classes will be available, because they are simply never loaded.

share|improve this answer
thanks for replying, oh i see, I did ran using jquery ajax call, which also returns the same error. so how do I load the functions? or how should i actually test it? – edward Jul 27 '13 at 11:02
thanks Johannes, i did some quick research, found my solution here:kynatro.com/blog/2012/12/11/… – edward Jul 27 '13 at 11:10
Yup, that is one of the approaches I was about to edit into the answer. Good find. As an aside, there is a multitude of answers on this stack detailing the same. – Johannes Pille Jul 27 '13 at 11:11
Here's a good one. – Johannes Pille Jul 27 '13 at 11:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.