{"id":5525,"date":"2016-02-05T13:29:02","date_gmt":"2016-02-05T21:29:02","guid":{"rendered":"http:\/\/www.dognmonkey.com\/techs\/?p=5525"},"modified":"2016-02-05T13:29:02","modified_gmt":"2016-02-05T21:29:02","slug":"warning-missing-argument-2-for-wpdbprepare-fixed","status":"publish","type":"post","link":"https:\/\/www.dognmonkey.com\/techs\/warning-missing-argument-2-for-wpdbprepare-fixed.html","title":{"rendered":"Warning: Missing argument 2 for wpdb::prepare() Fixed"},"content":{"rendered":"<p><em>When I used a footer that collects the earliest to the newest year to display from the dated posts, I got the &#8220;Warning: Missing argument 2 for wpdb::prepare()&#8221; on the bottom of the footer. After Googling the problem, I found the fix for it. It&#8217;s not a good way <a href=\"\/\/www.dognmonkey.com\/techs\/warning-missing-argument-2-for-wpdbprepare.html\" target=\"_blank\">to mask the problem like I did before<\/a>.<\/em><\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" rel=\"lightbox[wpdb]\" title=\"warning\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5526\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_1-200x76.jpg\" alt=\"wpdb_prepare_1\" width=\"200\" height=\"76\" \/><\/a>\u00a0 \u00a0 \u00a0<a title=\"missing 2nd argument\" class=\"preview\" rel=\"lightbox[wpdb]\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5527\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_2-200x80.jpg\" alt=\"wpdb_prepare_2\" width=\"200\" height=\"80\" \/><\/a><\/p>\n<p><em>The bad codes:<\/em><\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" rel=\"lightbox[wpdb]\" title=\"missing 2nd argument\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5528\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_3-200x112.jpg\" alt=\"wpdb_prepare_3\" width=\"200\" height=\"112\" \/><\/a><\/p>\n<blockquote><p><em>\u00a0$post_datetimes = $wpdb-&gt;get_row($wpdb-&gt;prepare(&#8220;SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb-&gt;posts WHERE post_date_gmt &gt; 1970&#8221;));<\/em><\/p><\/blockquote>\n<p><em>The good codes: We need to add the blank second argument to make it complete.&#8221;1970&#8243;,&#8217; &#8216;));&#8221;<\/em><\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" rel=\"lightbox[wpdb]\"  title=\"added 2nd argument\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_fixed.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5529\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/wpdb_prepare_fixed-200x112.jpg\" alt=\"wpdb_prepare_fixed\" width=\"200\" height=\"112\" \/><\/a><\/p>\n<blockquote><p>$post_datetimes = $wpdb-&gt;get_row($wpdb-&gt;prepare(&#8220;SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb-&gt;posts WHERE post_date_gmt &gt; 1970&#8221;,&#8217; &#8216;));<\/p><\/blockquote>\n<ul class=\"lcp_catlist\" id=\"lcp_instance_0\"><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When I used a footer that collects the earliest to the newest year to display from the dated posts, I got the &#8220;Warning: Missing argument 2 for wpdb::prepare()&#8221; on the bottom of the footer. After Googling the problem, I found the fix for it. It&#8217;s not a good way to mask the problem like I <a href=\"https:\/\/www.dognmonkey.com\/techs\/warning-missing-argument-2-for-wpdbprepare-fixed.html\" class=\"more-link\">&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[807,20],"tags":[808,362],"class_list":["post-5525","post","type-post","status-publish","format-standard","hentry","category-scripts","category-wordpress","tag-warningmissing-argument-2-for-wpdbprepare","tag-wpdbprepare"],"views":153,"_links":{"self":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/5525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/comments?post=5525"}],"version-history":[{"count":2,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/5525\/revisions"}],"predecessor-version":[{"id":5531,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/5525\/revisions\/5531"}],"wp:attachment":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/media?parent=5525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/categories?post=5525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/tags?post=5525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}