Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 31st Mar 2013, 05:41 PM   #1
Grouchy Old Geezer
War Room Member
 
Kirk Ward's Avatar
 
Join Date: 2006
Location: Ellijay, GA, USA. (Talk about being in the woods!)
Posts: 673
Thanks: 279
Thanked 62 Times in 47 Posts
Default
Non Object Error in Wordpress
Share on: 
fb share twitter share gplus share more share

I am creating a small plugin to update a database table.

The updater scriipt works properly when included in a Wordpress page or post template, but not when included in a script run by a form action from the plugin. (action="script.php")

This is the error:
fatal error call to a member function query on a non-object ...
where the error message references the fourth line of the code below where I am setting $result to the sql.
Code:
global $wpdb;
$table_name = $wpdb->prefix . "my_table_name";
$sql = "TRUNCATE " . $table_name;
$result = $wpdb->query($wpdb->prepare($sql));
From what I can find, which corresponds with what I suspected, the Wordpress framework, or whatever it is called, is not included in this small script, even though it is called by a plugin.

What is the correct way of getting the Wordpress functions, and framework, etc., loaded in this small script?

Many thanks for your consideration and help!
Kirk

"We are not here to sell a parcel of boilers and vats, but the potentiality of growing rich beyond the dreams of avarice."

Dr. Samuel Johnson (Presiding at the sale of Thrales brewery, London, 1781)
Kirk Ward is offline  
Unread 31st Mar 2013, 06:29 PM   #2
ResponsiveDesignTest.Net
Registered Member
 
Michael71's Avatar
 
Join Date: 2011
Location: Rostock, Germany
Posts: 829
Thanks: 106
Thanked 225 Times in 194 Posts
Default
Re: Non Object Error in Wordpress
Share on: 
fb share twitter share gplus share more share

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

HTML/CSS/jQuery/ZURB Foundation/Twitter Bootstrap/Wordpress/Frontend Performance Optimizing
---
Need HTML/CSS help? Skype: microcosmic - Test Your Responsive Design - InternetCookies.eu
Michael71 is offline  
The Following User Says Thank You to Michael71 For This Useful Post:
Unread 31st Mar 2013, 07:19 PM   #3
Grouchy Old Geezer
War Room Member
 
Kirk Ward's Avatar
 
Join Date: 2006
Location: Ellijay, GA, USA. (Talk about being in the woods!)
Posts: 673
Thanks: 279
Thanked 62 Times in 47 Posts
Default
Re: Non Object Error in Wordpress
Share on: 
fb share twitter share gplus share more share

Originally Posted by Michael71 View Post

require( './wp-load.php' ); (edit the path)
Awesome!

The script is at
Code:
/var/www/html/wp-content/plugins/my-plugin/my-file-name.php
and I used the server path,
Code:
/var/www/html/wp-load.php
It ran like a charm.

Next step is to get it to use a relative path. I'll keep working on that!

Many, many thanks!

"We are not here to sell a parcel of boilers and vats, but the potentiality of growing rich beyond the dreams of avarice."

Dr. Samuel Johnson (Presiding at the sale of Thrales brewery, London, 1781)
Kirk Ward is offline  
Unread 31st Mar 2013, 07:22 PM   #4
Grouchy Old Geezer
War Room Member
 
Kirk Ward's Avatar
 
Join Date: 2006
Location: Ellijay, GA, USA. (Talk about being in the woods!)
Posts: 673
Thanks: 279
Thanked 62 Times in 47 Posts
Default
Re: Non Object Error in Wordpress
Share on: 
fb share twitter share gplus share more share

P.S. - If the script allowed me to give more thanks, I'd have added three hundred and seventy-four just to start, with more to come later!

"We are not here to sell a parcel of boilers and vats, but the potentiality of growing rich beyond the dreams of avarice."

Dr. Samuel Johnson (Presiding at the sale of Thrales brewery, London, 1781)
Kirk Ward is offline  
Closed Thread


Bookmarks

Tags
error, object, wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 06:19 PM.