<?php\ninclude('admin\/custom_field.php');<\/code><\/pre><\/div>\n\n\n\n<?php\n\/\/ \u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u95a2\u308f\u308b\u8a18\u8ff0\u3092\u66f8\u3044\u3066\u3044\u304f\u3002<\/code><\/pre><\/div>\n\n\n\n<\/span>\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u308b<\/span><\/h3>\n\n\n\n<\/span>\u753b\u9762\u306b\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u30d5\u30c3\u30af\u3092\u4f5c\u6210<\/span><\/h4>\n\n\n\n<?php\nadd_action('admin_menu', 'add_music_field');<\/code><\/pre><\/div>\n\n\n\n\u3053\u308c\u306f\u7ba1\u7406\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u969b\u306b\u30d5\u30c3\u30af\u3055\u308c\u308b\u95a2\u6570\u3092\u6307\u5b9a\u3059\u308b\u3082\u306e\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u300c\u7ba1\u7406\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u304d\u306badd_music_field<\/code>\u3068\u3044\u3046\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3066\u306d\uff01\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<\/span>\u30dc\u30c3\u30af\u30b9\u3092\u4f5c\u6210<\/span><\/h4>\n\n\n\n\u3067\u306f\u3001\u5b9f\u969b\u306b\u5b9f\u884c\u3059\u308badd_music_field<\/code>\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<?php\n\/\/ \u524d\u7565\n\/\/ \u4ee5\u4e0b\u3092\u8ffd\u8a18\nfunction add_about_field() {\n \/\/ add_meta_box(\u8868\u793a\u3055\u308c\u308b\u30dc\u30c3\u30af\u30b9\u306eHTML\u306eID, \u30e9\u30d9\u30eb, \u8868\u793a\u3059\u308b\u5185\u5bb9\u3092\u4f5c\u6210\u3059\u308b\u95a2\u6570\u540d, \u6295\u7a3f\u30bf\u30a4\u30d7, \u8868\u793a\u65b9\u6cd5)\n add_meta_box( 'music-composer','\u4f5c\u66f2\u8005', 'create_form_music_composer', 'page', 'normal' );\n add_meta_box( 'music-lyrics','\u6b4c\u8a5e', 'create_form_music_lyrics', 'page', 'normal' );\n}<\/code><\/pre><\/div>\n\n\n\nadd_meta_box<\/code>\u306f\u6295\u7a3f\u753b\u9762\u306e\u300c\u30bf\u30b0\u300d\u3084\u300c\u30ab\u30c6\u30b4\u30ea\u30fc\u300d\u307f\u305f\u3044\u306a\u4e00\u3064\u306e\u7bb1\u3092\u4f5c\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n\n\n\n\u5927\u4e8b\u306a\u306e\u306f\u7b2c3\u301c5\u5f15\u6570\u3067\u3059\u3002<\/p>\n\n\n\n
\u7b2c3\u5f15\u6570\u3067\u306f\u8868\u793a\u3059\u308b\u5185\u5bb9\u3092\u4f5c\u6210\u3059\u308b\u95a2\u6570\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u6307\u5b9a\u3057\u305f\u95a2\u6570\u3067HTML\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n
\u7b2c4\u5f15\u6570\u306f”page”, “post”, “custom_post_type”\u306eslug\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u4ed6\u306b\u3082dashboard\u306a\u3069\u6307\u5b9a\u306f\u3067\u304d\u307e\u3059\u304c\u3001\u3053\u308c\u3089\u306f\u6295\u7a3f\u753b\u9762\u4ee5\u5916\u306b\u4f7f\u308f\u308c\u308b\u3082\u306e\u306a\u306e\u3067\u3001\u4eca\u56de\u306e\u7528\u9014\u3067\u306f\u3053\u308c\u3089\u306e3\u3064\u304f\u3089\u3044\u3057\u304b\u4f7f\u308f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002
\u7b2c5\u5f15\u6570\u306f’normal’, ‘side’, ‘advanced’\u306e3\u7a2e\u985e\u9078\u629e\u3067\u304d\u307e\u3059\u304c\u3001\u3053\u308c\u3089\u306f\u8868\u793a\u4f4d\u7f6e\u304c\u5909\u308f\u308a\u307e\u3059\u3002\u5177\u4f53\u7684\u306b\u3069\u3046\u306a\u308b\u306e\u304b\u306f\u8a66\u3057\u3066\u307f\u3066\u3082\u3089\u3048\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
<\/span>HTML\u3092\u51fa\u529b<\/span><\/h4>\n\n\n\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d5\u30a9\u30fc\u30e0\u306eHTML\u3092\u51fa\u529b\u3059\u308b\u90e8\u5206\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n
<?php\n\/\/ \u524d\u7565\n\/\/ \u3053\u3053\u304b\u3089\u8ffd\u8a18\nfunction create_form_music_composer(){\n global $post;\n echo '<input name="composer" style="width: 100%;" value="'.get_post_meta($post->ID,'composer',true).'"\/>';\n}\nfunction create_form_music_lyrics(){\n global $post;\n echo '<textarea name="lyrics" style="width: 100%; height: 200px;">'.get_post_meta($post->ID, 'lyrics', true).'<\/textarea>'\n \/\/ WYSIWYG\u30a8\u30c7\u30a3\u30bf\u3092\u4f7f\u3046\u3068\u304d\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\n \/\/ wp_editor( get_post_meta($post->ID,'lyrics',true), 'lyrics-box', ['textarea_name' => 'lyrics'] );\n}<\/code><\/pre><\/div>\n\n\n\n\u3053\u3053\u3067\u3001global $post<\/code>\u306f$post<\/code>\u3092\u4f7f\u3046\u305f\u3081\u306b\u5fc5\u8981\u306a\u306e\u3067\u3001\u66f8\u3044\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u3053\u3053\u307e\u3067\u3001\u3084\u3063\u3066\u304a\u3051\u3070\u3001\u6295\u7a3f\u753b\u9762\u306b\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<\/span>\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0<\/span><\/h3>\n\n\n\n\u6295\u7a3f\u753b\u9762\u306b\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u304c\u3001\u307e\u3060\u3001\u6295\u7a3f\u3057\u3066\u3082\u4fdd\u5b58\u306f\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n
\u6295\u7a3f\u3055\u308c\u305f\u3068\u304d\u3001\u3061\u3083\u3093\u3068\u4fdd\u5b58\u3055\u308c\u308b\u3088\u3046\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n
<\/span>\u6295\u7a3f\u3055\u308c\u305f\u6642\u306e\u30d5\u30c3\u30af\u3092\u4f5c\u6210<\/span><\/h4>\n\n\n\n<?php\n\/\/ \u524d\u7565\n\/\/ \u4ee5\u4e0b\u3092\u8ffd\u52a0\nadd_action('save_post', 'save_music_field');<\/code><\/pre><\/div>\n\n\n\n\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u6295\u7a3f\u3092\u4fdd\u5b58\u3059\u308b\u3068\u304d\u306fsave_music_field<\/code>\u95a2\u6570\u3092\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n\u3053\u306e\u95a2\u6570\u306e\u4e2d\u3067\u3001\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4fdd\u5b58\u3059\u308b\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n
<\/span>\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4fdd\u5b58<\/span><\/h4>\n\n\n\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308c\u3070\u3001\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4fdd\u5b58\u3067\u304d\u307e\u3059\u3002\u914d\u5217\u306b\u306f\u4f5c\u3063\u305f\u30d5\u30a9\u30fc\u30e0\u306ename<\/code>\u5c5e\u6027\u3092\u8a18\u8ff0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<?php\n\/\/ \u524d\u7565\n\/\/ \u3053\u3053\u304b\u3089\u8ffd\u8a18\nfunction save_music_field($post_id){\n $my_fields = ['composer', 'lyrics'];\n foreach($my_fields as $my_field){\n \/\/ $value\u306b\u4fdd\u5b58\u3059\u308b\u5024\u3092\u683c\u7d0d\u3059\u308b\n if(isset($_POST[$my_field])){\n $value=$_POST[$my_field];\n }else{\n $value='';\n }\n \/\/ $value\u304c\u3082\u3068\u3082\u3068\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3068\u304d\u306fupdate\u3057\u306a\u3044\n \/\/ $value\u304c\u7a7a\u306e\u3068\u304d\u306f\u524a\u9664\u3059\u308b\n if( strcmp($value, get_post_meta($post_id, $my_field, true)) != 0 ){\n update_post_meta($post_id, $my_field, $value);\n }elseif($value == ""){\n delete_post_meta($post_id, $my_field, get_post_meta($post_id, $my_field, true));\n }\n }\n}<\/code><\/pre><\/div>\n\n\n\n<\/span>\u307e\u3068\u3081<\/span><\/h3>\n\n\n\n\u307e\u3068\u3081\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306aadmin\/custom_field.php<\/code>\u304c\u51fa\u6765\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<?php\nadd_action('admin_menu', 'add_music_field');\nfunction add_about_field() {\n add_meta_box( 'music-composer','\u4f5c\u66f2\u8005', 'create_form_music_composer', 'page', 'normal' );\n add_meta_box( 'music-lyrics','\u6b4c\u8a5e', 'create_form_music_lyrics', 'page', 'normal' );\n}\n\nfunction create_form_music_composer(){\n global $post;\n echo '<input name="composer" style="width: 100%;" value="'.get_post_meta($post->ID,'composer',true).'"\/>';\n}\nfunction create_form_music_lyrics(){\n global $post;\n echo '<textarea name="lyrics" style="width: 100%; height: 200px;">'.get_post_meta($post->ID, 'lyrics', true).'<\/textarea>'\n \/\/ WYSIWYG\u30a8\u30c7\u30a3\u30bf\u3092\u4f7f\u3046\u3068\u304d\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\n \/\/ wp_editor( get_post_meta($post->ID,'lyrics',true), 'lyrics-box', ['textarea_name' => 'lyrics'] );\n}\n\nadd_action('save_post', 'save_music_field');\nfunction save_music_field($post_id){\n $my_fields = ['composer', 'lyrics'];\n foreach($my_fields as $my_field){\n if(isset($_POST[$my_field])){\n $value=$_POST[$my_field];\n }else{\n $value='';\n }\n if( strcmp($value, get_post_meta($post_id, $my_field, true)) != 0 ){\n update_post_meta($post_id, $my_field, $value);\n }elseif($value == ""){\n delete_post_meta($post_id, $my_field, get_post_meta($post_id, $my_field, true));\n }\n }\n}<\/code><\/pre><\/div>\n\n\n\n\u3053\u308c\u3089\u3092\u4f7f\u3048\u3070\u3001\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30d7\u30e9\u30b0\u30a4\u30f3\u306b\u983c\u3089\u305a\u3001\u30c6\u30fc\u30de\u3054\u3068\u306b\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n
\u3054\u89a7\u306e\u3068\u304a\u308a\u3001\u30b3\u30fc\u30c9\u304c\u9577\u304f\u306a\u308b\u306e\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u5206\u3051\u3066\u3084\u3089\u306a\u3044\u3068\u3001\u7ba1\u7406\u304c\u5927\u5909\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u306e\u3067\u3001functions.php<\/code>\u306finclude<\/code>\u6587\u3060\u3051\u3092\u8a18\u8ff0\u3057\u3066\u3001\u3044\u3044\u611f\u3058\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u5206\u3051\u3066\u3084\u308b\u306e\u304c\u30b9\u30de\u30fc\u30c8\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"WordPress\u306e\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u4f7f\u3044\u306b\u304f\u3044\u306e\u3067\u3001\u305d\u308c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u69d8\u3005\u306a\u30d7\u30e9\u30b0\u30a4\u30f3\u304c\u3042\u308a\u307e\u3059\u3002 \u305f\u3060\u3001\u3053\u308c\u3089\u3092\u4f7f\u3046\u3068\u3001\u958b\u767a\u74b0\u5883\u3067\u69cb\u7bc9\u3057\u305f\u3042\u3068\u3001\u672c\u756a\u74b0\u5883\u306b\u79fb\u3059\u3068\u304d\u3001\u518d\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u500b\u4eba\u7684\u306b\u3001WordP […]<\/p>\n","protected":false},"author":1,"featured_media":208465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[32,5],"tags":[39,33],"class_list":["post-4260","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-program","tag-php","tag-wordpress"],"aioseo_notices":[],"jetpack_featured_media_url":"http:\/\/cms.inter-arteq.com\/wp-content\/uploads\/2022\/03\/wordpress-how-to-create-custom-field-with-function-php.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/4260"}],"collection":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/comments?post=4260"}],"version-history":[{"count":3,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/4260\/revisions"}],"predecessor-version":[{"id":208464,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/4260\/revisions\/208464"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/media\/208465"}],"wp:attachment":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/media?parent=4260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/categories?post=4260"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/tags?post=4260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}