{"id":26355,"date":"2024-11-17T15:28:08","date_gmt":"2024-11-17T06:28:08","guid":{"rendered":"https:\/\/motoki-design.co.jp\/wordpress\/?p=26355"},"modified":"2024-11-17T15:28:08","modified_gmt":"2024-11-17T06:28:08","slug":"scf-to-acf-migration","status":"publish","type":"post","link":"https:\/\/motoki-design.co.jp\/wordpress\/scf-to-acf-migration\/","title":{"rendered":"WordPress\u2502SCF\u304b\u3089ACF\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u79fb\u884c\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<p>Smart Custom Fields (SCF) \u306e\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092 Advanced Custom Fields (ACF)\u306b\u79fb\u884c\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u5099\u5fd8\u9332\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SCF\u304b\u3089ACF\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u79fb\u884c\u3059\u308b\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u3084\u308a\u65b9\u306f\u7c21\u5358\u3067\u79fb\u884c\u306f\u4e00\u77ac\u3067\u5b8c\u4e86\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8b\u524d\u6e96\u5099<\/h3>\n\n\n\n<p>\u4e8b\u524d\u306bSCF\u3068ACF\u305d\u308c\u305e\u308c\u306b\u540c\u3058\u540d\u524d\u306e\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8a2d\u5b9a\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4eca\u56de\u306f\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306fwork\u3068\u3044\u3046\u6295\u7a3f\u30bf\u30a4\u30d7\u306b3\u3064\u683c\u7d0d\u3057\u3066\u304a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u30e9\u30d9\u30eb<\/th><th>\u540d\u524d<\/th><\/tr><\/thead><tbody><tr><td>\u30b5\u30a4\u30c8\u540d<\/td><td>site_name<\/td><\/tr><tr><td>URL<\/td><td>site_url<\/td><\/tr><tr><td>\u62c5\u5f53<\/td><td>work_info<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3042\u3068\u306ffunctions.php\u306b\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">SCF\u304b\u3089ACF\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u79fb\u884c<\/h3>\n\n\n\n<p>\u5916\u89b3\u3001\u30c6\u30fc\u30de\u30a8\u30c7\u30a3\u30bf\u304b\u3089functions.php\u306b\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"is-style-icon_pen\">\u30a8\u30e9\u30fc\u304c\u6016\u3044\u4eba\u306fCode Snippets\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u5165\u308c\u3066\u3001\u305d\u3053\u306b\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u3092\u6709\u52b9\u306b\u3002<\/p>\n\n\n\n<p>\u7ba1\u7406\u753b\u9762\u5de6\u4e0a\u306b\u300c<strong>ACF\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u4fdd\u5b58\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002<\/strong>\u300d\u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"is-style-icon_pen\">\u6295\u7a3f\u8a18\u4e8b\u306fpost\u3001\u56fa\u5b9a\u8a18\u4e8b\u306fpage\u306a\u306e\u3067\u3001\u597d\u304d\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>\n\/\/ ACF\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u518d\u4fdd\u5b58\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\nfunction update_acf_fields_for_works() {\n    \/\/ \u6307\u5b9a\u306e\u6295\u7a3f\u30bf\u30a4\u30d7\u306e\u6295\u7a3f\u3092\u53d6\u5f97\n    $args = [\n        &#39;post_type&#39;      =&gt; &#39;works&#39;,\n        &#39;posts_per_page&#39; =&gt; -1, \/\/ \u5168\u4ef6\u53d6\u5f97\n    ];\n    $query = new WP_Query($args);\n\n    if ($query-&gt;have_posts()) {\n        while ($query-&gt;have_posts()) {\n            $query-&gt;the_post();\n\n            $post_id = get_the_ID();\n\n            \/\/ \u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u518d\u4fdd\u5b58\n            $site_name = get_post_meta($post_id, &#39;site_name&#39;, true);\n            $site_url = get_post_meta($post_id, &#39;site_url&#39;, true);\n            $work_info = get_post_meta($post_id, &#39;work_info&#39;, true);\n\n            if ($site_name) {\n                update_field(&#39;site_name&#39;, $site_name, $post_id);\n            }\n            if ($site_url) {\n                update_field(&#39;site_url&#39;, $site_url, $post_id);\n            }\n            if ($work_info) {\n                update_field(&#39;work_info&#39;, $work_info, $post_id);\n            }\n        }\n\n        wp_reset_postdata();\n        echo &quot;ACF\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u4fdd\u5b58\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002&quot;;\n    } else {\n        echo &quot;\u6307\u5b9a\u306e\u6295\u7a3f\u30bf\u30a4\u30d7\u306b\u8a18\u4e8b\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;;\n    }\n}\n\n\/\/ \u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u30d5\u30c3\u30af\u3092\u8a2d\u5b9a\nadd_action(&#39;init&#39;, &#39;update_acf_fields_for_works&#39;);<\/code><\/pre><\/div>\n\n\n\n<p>\u6700\u5f8c\u306b\u5bfe\u8c61\u8a18\u4e8b\u3092\u958b\u3044\u3066\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u4e21\u65b9\u3042\u308b\u304b\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Smart Custom Fields (SCF) \u306e\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092 Advanced Custom Fields (ACF)\u306b\u79fb\u884c\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u305d\u306e\u5099\u5fd8\u9332\u3067\u3059\u3002 SCF\u304b\u3089ACF\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u79fb\u884c\u3059\u308b\u65b9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":26358,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pochipp_cv_data":"","swell_btn_cv_data":"","footnotes":""},"categories":[91],"tags":[],"area":[],"class_list":["post-26355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-customize"],"_links":{"self":[{"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/posts\/26355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/comments?post=26355"}],"version-history":[{"count":3,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/posts\/26355\/revisions"}],"predecessor-version":[{"id":26359,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/posts\/26355\/revisions\/26359"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/media\/26358"}],"wp:attachment":[{"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/media?parent=26355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/categories?post=26355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/tags?post=26355"},{"taxonomy":"area","embeddable":true,"href":"https:\/\/motoki-design.co.jp\/wordpress\/wp-json\/wp\/v2\/area?post=26355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}