{"id":312,"date":"2020-03-18T18:11:07","date_gmt":"2020-03-18T10:11:07","guid":{"rendered":"https:\/\/heoffice.com\/?p=312"},"modified":"2020-05-02T15:12:07","modified_gmt":"2020-05-02T07:12:07","slug":"rest-full-api-%e4%b8%ad%e6%b7%bb%e5%8a%a0wti-like-post-%e6%8f%92%e4%bb%b6%e7%9a%84%e5%96%9c%e6%ac%a2%e6%95%b0%e3%80%82","status":"publish","type":"post","link":"https:\/\/heoffice.com\/?p=312","title":{"rendered":"Rest FUll API \u4e2d\u6dfb\u52a0WTI LIKE POST \u63d2\u4ef6\u7684\u559c\u6b22\u6570\u3002"},"content":{"rendered":"\n<p>WordPress \u7684 WTI LIKE POST \u63d2\u4ef6\u7684\u559c\u6b22\u6570\u9ed8\u8ba4\u662f\u6dfb\u52a0\u5728Content\u4e2d\u7684\uff0c\u800c\u5728Wordpress \u7684REST FULL API  \u4e2d\u6ca1\u6709\u559c\u6b22\u6570\u76f8\u5173\u5b57\u6bb5\uff0c\u53ea\u9700\u5728wti_like_post.php\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u5c31\u80fd\u591f\u5728RESTFULL API\u4e2d\u6dfb\u52a0likes\u5b57\u6bb5\u4e86\uff1a<\/p>\n\n\n\n<p><code>add_action( 'rest_api_init', function () {<br>      register_rest_field( 'post', 'likes', array(<br>          'get_callback' =&gt; function( $post_arr ) {<br>            return GetWtiLikeCount($post_arr['id']);<br>          },<br>          'schema' =&gt; array(<br>              'description' =&gt; __( 'Likes .' ),<br>              'type'        =&gt; 'integer'<br>          ),<br>      ) );<br>  } );<\/code><\/p>\n\n\n\n<p>\u5f53API\u8bf7\u6c42\u65f6\uff0c\u6587\u7ae0\u5185\u5bb9\u4e2d\u4e0d\u663e\u793a\u70b9\u8d5e\u6309\u94ae, \u5728wti_like_post_site.php\u4e2d\u7684\u51fd\u6570function PutWtiLikePost($content) \u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c<\/p>\n\n\n\n<p><code>if( isset($_SERVER['REQUEST_URI']) &amp;&amp; strpos($_SERVER['REQUEST_URI'],'\/wp-json\/wp\/v2\/')!== false ){<br>           $show_on_pages = false;<br>  }<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/developer.wordpress.org\/rest-api\/extending-the-rest-api\/modifying-responses\/#how-register_rest_field-works\">https:\/\/developer.wordpress.org\/rest-api\/extending-the-rest-api\/modifying-responses\/#how-register_rest_field-works<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress \u7684 WTI LIKE POST \u63d2\u4ef6\u7684\u559c\u6b22\u6570\u9ed8\u8ba4\u662f\u6dfb\u52a0\u5728Content\u4e2d\u7684\uff0c\u800c\u5728Wordp&#8230;<\/p>\n","protected":false},"author":1,"featured_media":330,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3,1,8],"tags":[],"class_list":["post-312","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-web","category-wordpress"],"acf":[],"_links":{"self":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=312"}],"version-history":[{"count":4,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/312\/revisions"}],"predecessor-version":[{"id":332,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/312\/revisions\/332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/media\/330"}],"wp:attachment":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}