scripts | WordPress

Warning: Missing argument 2 for wpdb::prepare()

August 7, 2013 / 299 views

With all the new database version and WordPress updates, sometimes I get the warning from the footer scripts. This time with the WP 3.6 update.

Warning: Missing argument 2 for wpdb::prepare(), called in C:\xampp\htdocs\wp36\wp-content\themes\i2010techs13\footer.php on line 28 and defined in C:\xampp\htdocs\wp36\wp-includes\wp-db.php on line 992

wpdbwarning

The fix is to add the code to config.php file – anywhere.

@ini_set(‘display_errors’, 0);

configfix

This is the script I added to extract the date of the first post and the last post of my blog.

<?php
global $wpdb;
$post_datetimes = $wpdb->get_row($wpdb->prepare(“SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970”));
if ($post_datetimes) {
$firstpost_year = $post_datetimes->firstyear;
$lastpost_year = $post_datetimes->lastyear;
$copyright = __(‘Copyright &copy;&nbsp; ‘, ‘idog’) . $firstpost_year;
if($firstpost_year != $lastpost_year) {
$copyright .= ‘-‘. $lastpost_year;
}
$copyright .= ‘ ‘;
echo $copyright;
}

Paid Links

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.