{"id":1898,"date":"2021-11-01T22:57:38","date_gmt":"2021-11-01T13:57:38","guid":{"rendered":"https:\/\/417.run\/?p=1898"},"modified":"2021-12-18T11:40:31","modified_gmt":"2021-12-18T02:40:31","slug":"wp-insert-post","status":"publish","type":"post","link":"https:\/\/417.run\/pg\/wp-dev\/wp-insert-post\/","title":{"rendered":"\u3010Wordpres\u958b\u767a\u3011\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8a18\u4e8b\u3092\u6295\u7a3f\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_17 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u6b21<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/417.run\/pg\/wp-dev\/wp-insert-post\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%A7%E8%A8%98%E4%BA%8B%E3%82%92%E6%8A%95%E7%A8%BF%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\" title=\"\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8a18\u4e8b\u3092\u6295\u7a3f\u3059\u308b\u65b9\u6cd5\">\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8a18\u4e8b\u3092\u6295\u7a3f\u3059\u308b\u65b9\u6cd5<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/417.run\/pg\/wp-dev\/wp-insert-post\/#%E8%A8%98%E4%BA%8B%E3%81%AB%E3%83%A1%E3%82%BF%E3%83%87%E3%83%BC%E3%82%BF%E3%82%92%E3%81%A4%E3%81%91%E3%82%8B%E6%96%B9%E6%B3%95\" title=\"\u8a18\u4e8b\u306b\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u3064\u3051\u308b\u65b9\u6cd5\">\u8a18\u4e8b\u306b\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u3064\u3051\u308b\u65b9\u6cd5<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/417.run\/pg\/wp-dev\/wp-insert-post\/#%E3%83%A1%E3%82%BF%E3%83%87%E3%83%BC%E3%82%BF%E3%81%A8%E3%81%AF\" title=\"\u30e1\u30bf\u30c7\u30fc\u30bf\u3068\u306f\">\u30e1\u30bf\u30c7\u30fc\u30bf\u3068\u306f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/417.run\/pg\/wp-dev\/wp-insert-post\/#%E3%83%91%E3%83%A9%E3%83%A1%E3%83%BC%E3%82%BF\" title=\"\u30d1\u30e9\u30e1\u30fc\u30bf\">\u30d1\u30e9\u30e1\u30fc\u30bf<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%A7%E8%A8%98%E4%BA%8B%E3%82%92%E6%8A%95%E7%A8%BF%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8a18\u4e8b\u3092\u6295\u7a3f\u3059\u308b\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-php\">$id = wp_insert_post([\n    &#039;post_title&#039; =&gt; $title,\n    &#039;post_content&#039; =&gt; $content,\n    &#039;post_type&#039; =&gt; &#039;post&#039;,\n]);<\/code><\/pre>\n<p>\u305d\u306e\u4ed6\u306e\u30d1\u30e9\u30e1\u30fc\u30bf<\/p>\n<pre><code class=\"language-php\">  &#039;ID&#039;             =&gt; [ &lt;\u6295\u7a3f ID&gt; ] \/\/ \u65e2\u5b58\u306e\u6295\u7a3f\u3092\u66f4\u65b0\u3059\u308b\u5834\u5408\u306b\u6307\u5b9a\u3002\n  &#039;post_content&#039;   =&gt; [ &lt;\u6587\u5b57\u5217&gt; ] \/\/ \u6295\u7a3f\u306e\u5168\u6587\u3002\n  &#039;post_name&#039;      =&gt; [ &lt;\u6587\u5b57\u5217&gt; ] \/\/ \u6295\u7a3f\u306e\u30b9\u30e9\u30c3\u30b0\u3002\n  &#039;post_title&#039;     =&gt; [ &lt;\u6587\u5b57\u5217&gt; ] \/\/ \u6295\u7a3f\u306e\u30bf\u30a4\u30c8\u30eb\u3002\n  &#039;post_status&#039;    =&gt; [ &#039;draft&#039; | &#039;publish&#039; | &#039;pending&#039;| &#039;future&#039; | &#039;private&#039; | \u767b\u9332\u6e08\u307f\u30ab\u30b9\u30bf\u30e0\u30b9\u30c6\u30fc\u30bf\u30b9 ] \/\/ \u516c\u958b\u30b9\u30c6\u30fc\u30bf\u30b9\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f &#039;draft&#039;\u3002\n  &#039;post_type&#039;      =&gt; [ &#039;post&#039; | &#039;page&#039; | &#039;link&#039; | &#039;nav_menu_item&#039; | \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30bf\u30a4\u30d7 ] \/\/ \u6295\u7a3f\u30bf\u30a4\u30d7\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f &#039;post&#039;\u3002\n  &#039;post_author&#039;    =&gt; [ &lt;\u30e6\u30fc\u30b6\u30fc ID&gt; ] \/\/ \u4f5c\u6210\u8005\u306e\u30e6\u30fc\u30b6\u30fc ID\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u30ed\u30b0\u30a4\u30f3\u4e2d\u306e\u30e6\u30fc\u30b6\u30fc\u306e ID\u3002\n  &#039;ping_status&#039;    =&gt; [ &#039;closed&#039; | &#039;open&#039; ] \/\/ &#039;open&#039; \u306a\u3089\u30d4\u30f3\u30d0\u30c3\u30af\u30fb\u30c8\u30e9\u30c3\u30af\u30d0\u30c3\u30af\u3092\u8a31\u53ef\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u30aa\u30d7\u30b7\u30e7\u30f3 &#039;default_ping_status&#039; \u306e\u5024\u3002\n  &#039;post_parent&#039;    =&gt; [ &lt;\u6295\u7a3f ID&gt; ] \/\/ \u89aa\u6295\u7a3f\u306e ID\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f 0\u3002\n  &#039;menu_order&#039;     =&gt; [ &lt;\u9806\u5e8f\u5024&gt; ] \/\/ \u56fa\u5b9a\u30da\u30fc\u30b8\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u3001\u30e1\u30cb\u30e5\u30fc\u5185\u306e\u4e26\u3073\u9806\u3092\u6307\u5b9a\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f 0\u3002\n  &#039;to_ping&#039;        =&gt; \/\/ \u30b9\u30da\u30fc\u30b9\u307e\u305f\u306f\u6539\u884c\u3067\u533a\u5207\u3063\u305f\u3001\u30d4\u30f3\u3092\u6253\u3064\u4e88\u5b9a\u306e URL \u306e\u30ea\u30b9\u30c8\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u6587\u5b57\u5217\u3002\n  &#039;pinged&#039;         =&gt; \/\/ \u30b9\u30da\u30fc\u30b9\u307e\u305f\u306f\u6539\u884c\u3067\u533a\u5207\u3063\u305f\u3001\u30d4\u30f3\u3092\u6253\u3063\u305f URL \u306e\u30ea\u30b9\u30c8\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u6587\u5b57\u5217\u3002\n  &#039;post_password&#039;  =&gt; [ &lt;\u6587\u5b57\u5217&gt; ] \/\/ \u6295\u7a3f\u30d1\u30b9\u30ef\u30fc\u30c9\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u6587\u5b57\u5217\u3002\n  &#039;guid&#039;           =&gt; \/\/ \u666e\u901a\u306f\u3053\u308c\u3092\u6307\u5b9a\u305b\u305a WordPress \u306b\u4efb\u305b\u3066\u304f\u3060\u3055\u3044\u3002\n  &#039;post_content_filtered&#039; =&gt; \/\/ \u666e\u901a\u306f\u3053\u308c\u3092\u6307\u5b9a\u305b\u305a WordPress \u306b\u4efb\u305b\u3066\u304f\u3060\u3055\u3044\u3002\n  &#039;post_excerpt&#039;   =&gt; [ &lt;\u6587\u5b57\u5217&gt; ] \/\/ \u6295\u7a3f\u306e\u629c\u7c8b\u3002\n  &#039;post_date&#039;      =&gt; [ Y-m-d H:i:s ] \/\/ \u6295\u7a3f\u306e\u4f5c\u6210\u65e5\u6642\u3002\n  &#039;post_date_gmt&#039;  =&gt; [ Y-m-d H:i:s ] \/\/ \u6295\u7a3f\u306e\u4f5c\u6210\u65e5\u6642\uff08GMT\uff09\u3002\n  &#039;comment_status&#039; =&gt; [ &#039;closed&#039; | &#039;open&#039; ] \/\/ &#039;open&#039; \u306a\u3089\u30b3\u30e1\u30f3\u30c8\u3092\u8a31\u53ef\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u30aa\u30d7\u30b7\u30e7\u30f3 &#039;default_comment_status&#039; \u306e\u5024\u3001\u307e\u305f\u306f &#039;closed&#039;\u3002\n  &#039;post_category&#039;  =&gt; [ array(&lt;\u30ab\u30c6\u30b4\u30ea\u30fc ID&gt;, ...) ] \/\/ \u6295\u7a3f\u30ab\u30c6\u30b4\u30ea\u30fc\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\uff08\u30ab\u30c6\u30b4\u30ea\u30fc\u306a\u3057\uff09\u3002\n  &#039;tags_input&#039;     =&gt; [ &#039;&lt;tag&gt;, &lt;tag&gt;, ...&#039; | array ] \/\/ \u6295\u7a3f\u30bf\u30b0\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\uff08\u30bf\u30b0\u306a\u3057\uff09\u3002\n  &#039;tax_input&#039;      =&gt; [ array( &lt;\u30bf\u30af\u30bd\u30ce\u30df\u30fc&gt; =&gt; &lt;array | string&gt;, ...) ] \/\/ \u30ab\u30b9\u30bf\u30e0\u30bf\u30af\u30bd\u30ce\u30df\u30fc\u3068\u30bf\u30fc\u30e0\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u3002\n  &#039;page_template&#039;  =&gt; [ &lt;\u6587\u5b57\u5217&gt; ] \/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u540d\u524d\u3001\u4f8b\u3048\u3070 template.php \u7b49\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u3002<\/code><\/pre>\n<p>\u53c2\u8003: <a href=\"https:\/\/wpdocs.osdn.jp\/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9\/wp_insert_post\">https:\/\/wpdocs.osdn.jp\/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9\/wp_insert_post<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E8%A8%98%E4%BA%8B%E3%81%AB%E3%83%A1%E3%82%BF%E3%83%87%E3%83%BC%E3%82%BF%E3%82%92%E3%81%A4%E3%81%91%E3%82%8B%E6%96%B9%E6%B3%95\"><\/span>\u8a18\u4e8b\u306b\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u3064\u3051\u308b\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-php\">add_post_meta($id, &#039;meta_key&#039;, $val, true);<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%A1%E3%82%BF%E3%83%87%E3%83%BC%E3%82%BF%E3%81%A8%E3%81%AF\"><\/span>\u30e1\u30bf\u30c7\u30fc\u30bf\u3068\u306f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u57fa\u672c\u306e\u30c7\u30fc\u30bf\u3068\u306f\u5225\u306b\u307b\u304b\u306e\u30c7\u30fc\u30bf\u3092\u3064\u3051\u305f\u3044\u5834\u5408\u306b\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%91%E3%83%A9%E3%83%A1%E3%83%BC%E3%82%BF\"><\/span>\u30d1\u30e9\u30e1\u30fc\u30bf<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-doc\">$post_id\n\uff08\u6574\u6570\uff09 \uff08\u5fc5\u9808\uff09 \u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u6295\u7a3f\u306e ID\u3002\n\u521d\u671f\u5024\uff1a \u306a\u3057\n$meta_key\n\uff08\u6587\u5b57\u5217\uff09 \uff08\u5fc5\u9808\uff09 \u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30ad\u30fc\u3002\n\u521d\u671f\u5024\uff1a \u306a\u3057\n$meta_value\n\uff08mixed\uff09 \uff08\u5fc5\u9808\uff09 \u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3002\u914d\u5217\u3092\u4e0e\u3048\u308b\u3068\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3055\u308c\u3066\u6587\u5b57\u5217\u304c\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002\n\u521d\u671f\u5024\uff1a \u306a\u3057\n$unique\n\uff08\u771f\u507d\u5024\uff09 \uff08\u30aa\u30d7\u30b7\u30e7\u30f3\uff09 \u30ad\u30fc\u3092\u30e6\u30cb\u30fc\u30af\u306b\u3059\u308b\u304b\u3069\u3046\u304b\u3002true \u306e\u3068\u304d\u306f\u3001\u6307\u5b9a\u3057\u305f\u6295\u7a3f\u306b $meta_key \u3092\u6301\u3064\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u7121\u3044\u3068\u304d\u306e\u307f\u8ffd\u52a0\u3057\u3001\u3059\u3067\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u5b58\u5728\u3057\u3066\u3044\u308c\u3070\u8ffd\u52a0\u3055\u308c\u307e\u305b\u3093\u3002\n\u521d\u671f\u5024\uff1a false<\/code><\/pre>\n<p>\u53c2\u8003: <a href=\"https:\/\/wpdocs.osdn.jp\/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9\/add_post_meta\">https:\/\/wpdocs.osdn.jp\/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9\/add_post_meta<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 \u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8a18\u4e8b\u3092\u6295\u7a3f\u3059\u308b\u65b9\u6cd5\u8a18\u4e8b\u306b\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u3064\u3051\u308b\u65b9\u6cd5\u30e1\u30bf\u30c7\u30fc\u30bf\u3068\u306f\u30d1\u30e9\u30e1\u30fc\u30bf \u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8a18\u4e8b\u3092\u6295\u7a3f\u3059\u308b\u65b9\u6cd5 $id = wp_insert_post([ &#039;post_title&#039; =&#038;g &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[22],"class_list":{"0":"post-1898","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-wp-dev","7":"tag-wordpress","8":"nothumb"},"_links":{"self":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/1898"}],"collection":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/comments?post=1898"}],"version-history":[{"count":6,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/1898\/revisions"}],"predecessor-version":[{"id":2420,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/1898\/revisions\/2420"}],"wp:attachment":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/media?parent=1898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/categories?post=1898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/tags?post=1898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}