{"id":714,"date":"2019-11-27T17:58:41","date_gmt":"2019-11-27T09:58:41","guid":{"rendered":"http:\/\/blog.yyhcw.com\/?p=714"},"modified":"2019-11-27T17:59:25","modified_gmt":"2019-11-27T09:59:25","slug":"wordpress-%e8%ae%bf%e9%97%ae%e4%b8%8d%e5%90%8c%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/blog.yyhcw.com\/post\/714.html","title":{"rendered":"wordpress \u8fde\u63a5\u4e0d\u540c\u6570\u636e\u5e93\u65b9\u6cd5"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u6211\u7684\u9700\u6c42\u53ef\u80fd\u6bd4\u8f83\u5947\u8469\u5427\uff01\u9700\u8981\u51e0\u4e2a\u7f51\u7ad9\u7684\u6570\u636e\u90fd\u4f7f\u7528\u4e00\u4e2a\u8868\u91cc\u9762\u7684\uff0c\u53c8\u4e0d\u60f3\u6bcf\u4e2a\u7f51\u7ad9\u90fd\u5efa\u7acb\u76f8\u540c\u7684\u6570\u636e\u8868\uff0c\u5219\u5c31\u60f3\u5230\u94fe\u63a5\u540c\u4e00\u4e2a\u6570\u636e\u5e93\u8868\u4e86\uff01\u8fd9\u4e2a\u4e5f\u53ef\u7406\u89e3\u4e3a\u7ad9\u7fa4\u7684\u4e00\u79cd\u5427\uff01\u6bd4\u5982\uff1aN\u591a\u4e2a\u7f51\u7ad9\u516c\u7528\u4e00\u4e2a\u7528\u6237\u6570\u636e\u5e93\uff0c\u5b9e\u73b0\u7528\u6237\u540c\u6b65\u767b\u5f55\u3001\u9000\u51fa\u64cd\u4f5c\uff0c\u6216\u8005\u6587\u7ae0\u8fdb\u884c\u5206\u7c7b\u663e\u793a\u4e0e\u4e0d\u540c\u7684\u7f51\u7ad9\u4e0a\u9762\uff01\u7b49\u7b49\u5427\uff0c\u6839\u636e\u4e2a\u4eba\u601d\u8def\u4e0d\u540c\u968f\u610f\u6269\u5c55\u3002<\/p>\n<p>\u56e0\u4e3a\u6211\u9700\u8981\u7684\u662f<a href=\"https:\/\/blog.yyhcw.com\/post\/tag\/wordpress\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e wordpress \u7684\u6587\u7ae0\" target=\"_blank\">wordpress<\/a>\u67d0\u4e2a\u9875\u9762\u5355\u72ec\u8bbf\u95ee\u4e0d\u540c\u670d\u52a1\u5668\u4e0a\u7684\u76f8\u540c\u7684\u6570\u636e\u5e93\uff0c\u5219\u76f4\u63a5\u5728\u6a21\u677f\u6587\u4ef6\u4e2d\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\u5373\u53ef\uff1a<\/p>\n<pre class=\"lang:php decode:true \">\/\/ \u6570\u636e\u5e93\u914d\u7f6e\u53c2\u6570 \u6839\u636e\u4e2a\u4eba\u6570\u636e\u5e93\u60c5\u51b5\u4fee\u6539\u4e0b\u9762\u8fde\u63a5\u4fe1\u606f\u5373\u53ef\r\n$mydb = new wpdb('username','password','database','localhost');\r\n$rows = $mydb-&gt;get_results(\"select Name from my_table\");\r\necho \"&lt;ul class='blog.yyhcw.com'&gt;\";\r\nforeach ($rows as $obj) :\r\n   echo \"&lt;li&gt;\".$obj-&gt;Name.\"&lt;\/li&gt;\";\r\nendforeach;\r\necho \"&lt;\/ul&gt;\";<\/pre>\n<p>\u521b\u5efa\u8fde\u63a5\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528 <a href=\"https:\/\/blog.yyhcw.com\/post\/tag\/wordpress\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e wordpress \u7684\u6587\u7ae0\" target=\"_blank\">wordpress<\/a> \u81ea\u5e26\u7684\u4e00\u4e9b\u6570\u636e\u5e93\u51fd\u6570\u4e86<\/p>\n<pre class=\"lang:php decode:true\">$sum = $wpdb-&gt;get_var( $wpdb-&gt;prepare( \"SELECT COUNT(*) from table_name where post_status = 'publish' and user_id = %d\", $user_id ) );\r\n \r\nprintf('This user has %d posts', $sum);\r\n<\/pre>\n<p>OK\uff0c\u662f\u4e0d\u662f\u4f60\u7684<a href=\"https:\/\/blog.yyhcw.com\/post\/tag\/wordpress\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e wordpress \u7684\u6587\u7ae0\" target=\"_blank\">wordpress<\/a>\u53ef\u4ee5\u8fde\u63a5N\u591a\u4e2a\u4e0d\u540c\u670d\u52a1\u5668\u4e0a\u7684\u6570\u636e\u5e93\u4e86\uff0c\u4e3a\u6240\u6b32\u4e3a\u5427\uff01<\/p>\n<p>wordpress \u5185\u7f6e\u7684\u6570\u636e\u5e93\u7c7b\u7684\u64cd\u4f5c\u8bf7\u67e5\u770b\u4ee5\u4e0b\u5b98\u65b9\u94fe\u63a5\uff1a <a href=\"https:\/\/codex.wordpress.org\/Class_Reference\/wpdb#Protect_Queries_Against_SQL_Injection_Attacks\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress\u5b98\u65b9\u6570\u636e\u5e93\u64cd\u4f5c\u8bf4\u660e<\/a><\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u6211\u7684\u9700\u6c42\u53ef\u80fd\u6bd4\u8f83\u5947\u8469\u5427\uff01\u9700\u8981\u51e0\u4e2a\u7f51\u7ad9\u7684\u6570\u636e\u90fd\u4f7f\u7528\u4e00\u4e2a\u8868\u91cc\u9762\u7684\uff0c\u53c8\u4e0d\u60f3\u6bcf\u4e2a\u7f51\u7ad9\u90fd\u5efa\u7acb\u76f8\u540c\u7684\u6570\u636e\u8868\uff0c\u5219\u5c31\u60f3\u5230\u94fe\u63a5\u540c \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[28],"views":525,"_links":{"self":[{"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts\/714"}],"collection":[{"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/comments?post=714"}],"version-history":[{"count":0,"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts\/714\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/media?parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/categories?post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.yyhcw.com\/api\/wp\/v2\/tags?post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}