PHP Retrieving Value from MySql Error

weavermagenta

New Member
I have a php script that I've put together from examples on the internet.I'm not very familiar with php and I'm getting an error.I am trying to get the last post date of my Wordpress blog for my program to show when the last date that we put important information for the user on it.This is my code:\[code\] <?php function lpd_post_date( $date_format, $echo, $modified_date = false ) { $dbhost = 'xxx'; $dbuser = 'xxx'; $dbpass = 'xxx'; $dbname = 'xxx'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); // include 'config.php'; // include 'opendb.php'; global $wpdb; $date_col = 'post_date'; if ( $modified_date ) $date_col = 'post_modified'; $sql = " SELECT $date_col FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type = 'post' ORDER BY $date_col DESC LIMIT 1 "; $mysql_date = $wpdb->get_var( $sql ); if ( ! $date_format ) $date_format = get_option('date_format'); $formatted_date = mysql2date( $date_format, $mysql_date ); echo $formatted_date; mysql_close($conn); }?>\[/code\]I am getting this error:\[quote\] Fatal error: Call to a member function on a non-object in /homepages/38/d157689362/htdocs/suburban/updates/last/last.php on line 21\[/quote\]Anyone able to help me out? I'm lost as to what it is doing on line 21:\[quote\] $mysql_date = $wpdb->get_var( $sql );\[/quote\]Any help would be greatly appreciated!Thanks!
 
Back
Top