{"id":4230,"date":"2022-08-22T00:45:03","date_gmt":"2022-08-21T19:15:03","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/"},"modified":"2022-08-22T00:45:03","modified_gmt":"2022-08-21T19:15:03","slug":"solved-create-more-meta-boxes-as-needed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/","title":{"rendered":"[Solved] Create more Meta Boxes as needed"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-19852\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"19852\" data-parentid=\"19838\" data-score=\"56\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>So you mean something like this?<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png\" alt=\"enter image description here\"><\/p>\n<p>and when you click on Add tracks it becomes this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/1661109303_565_Solved-Create-more-Meta-Boxes-as-needed.png\" alt=\"enter image description here\"><\/p>\n<p>if  it is what you mean the its done by creating a metabox that has simple jquery function to add and remove fields in it, and the data is saved as an array in of data in a single meta row, here you go:<\/p>\n<pre><code>  add_action( 'add_meta_boxes', 'dynamic_add_custom_box' );\n\n    \/* Do something with the data entered *\/\n    add_action( 'save_post', 'dynamic_save_postdata' );\n\n    \/* Adds a box to the main column on the Post and Page edit screens *\/\n    function dynamic_add_custom_box() {\n        add_meta_box(\n            'dynamic_sectionid',\n            __( 'My Tracks', 'myplugin_textdomain' ),\n            'dynamic_inner_custom_box',\n            'post');\n    }\n\n    \/* Prints the box content *\/\n    function dynamic_inner_custom_box() {\n        global $post;\n        \/\/ Use nonce for verification\n        wp_nonce_field( plugin_basename( __FILE__ ), 'dynamicMeta_noncename' );\n        ?&gt;\n        &lt;div id=\"meta_inner\"&gt;\n        &lt;?php\n\n        \/\/get the saved meta as an array\n        $songs = get_post_meta($post-&gt;ID,'songs',false);\n\n        $c = 0;\n        if ( count( $songs ) &gt; 0 ) {\n            foreach( $songs as $track ) {\n                if ( isset( $track['title'] ) || isset( $track['track'] ) ) {\n                    printf( '&lt;p&gt;Song Title &lt;input type=\"text\" name=\"songs[%1$s]Create more Meta Boxes as needed\" value=\"%2$s\" \/&gt; -- Track number : &lt;input type=\"text\" name=\"songs[%1$s][track]\" value=\"%3$s\" \/&gt;&lt;span class=\"remove\"&gt;%4$s&lt;\/span&gt;&lt;\/p&gt;', $c, $track['title'], $track['track'], __( 'Remove Track' ) );\n                    $c = $c +1;\n                }\n            }\n        }\n\n        ?&gt;\n    &lt;span id=\"here\"&gt;&lt;\/span&gt;\n    &lt;span class=\"add\"&gt;&lt;?php _e('Add Tracks'); ?&gt;&lt;\/span&gt;\n    &lt;script&gt;\n        var $ =jQuery.noConflict();\n        $(document).ready(function() {\n            var count = &lt;?php echo $c; ?&gt;;\n            $(\".add\").click(function() {\n                count = count + 1;\n\n                $('#here').append('&lt;p&gt; Song Title &lt;input type=\"text\" name=\"songs['+count+']Create more Meta Boxes as needed\" value=\"\" \/&gt; -- Track number : &lt;input type=\"text\" name=\"songs['+count+'][track]\" value=\"\" \/&gt;&lt;span class=\"remove\"&gt;Remove Track&lt;\/span&gt;&lt;\/p&gt;' );\n                return false;\n            });\n\/\/ The live() method was deprecated in jQuery version 1.7, and removed in version 1.9. Use the on() method instead. We can use .on\n            $(\".remove\").live('click', function() {\n                $(this).parent().remove();\n            });\n        });\n        &lt;\/script&gt;\n    &lt;\/div&gt;&lt;?php\n\n    }\n\n    \/* When the post is saved, saves our custom data *\/\n    function dynamic_save_postdata( $post_id ) {\n        \/\/ verify if this is an auto save routine. \n        \/\/ If it is our form has not been submitted, so we dont want to do anything\n        if ( defined( 'DOING_AUTOSAVE' ) &amp;&amp; DOING_AUTOSAVE ) \n            return;\n\n        \/\/ verify this came from the our screen and with proper authorization,\n        \/\/ because save_post can be triggered at other times\n        if ( !isset( $_POST['dynamicMeta_noncename'] ) )\n            return;\n\n        if ( !wp_verify_nonce( $_POST['dynamicMeta_noncename'], plugin_basename( __FILE__ ) ) )\n            return;\n\n        \/\/ OK, we're authenticated: we need to find and save the data\n\n        $songs = $_POST['songs'];\n\n        update_post_meta($post_id,'songs',$songs);\n    }\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">15<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Create more Meta Boxes as needed <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] So you mean something like this? and when you click on Add tracks it becomes this: if it is what you mean the its done by creating a metabox that has simple jquery function to add and remove fields in it, and the data is saved as an array in of data in a &#8230; <a title=\"[Solved] Create more Meta Boxes as needed\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\" aria-label=\"More on [Solved] Create more Meta Boxes as needed\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[627],"tags":[711],"class_list":["post-4230","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-metabox"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Create more Meta Boxes as needed - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Create more Meta Boxes as needed - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] So you mean something like this? and when you click on Add tracks it becomes this: if it is what you mean the its done by creating a metabox that has simple jquery function to add and remove fields in it, and the data is saved as an array in of data in a ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-21T19:15:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Create more Meta Boxes as needed\",\"datePublished\":\"2022-08-21T19:15:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\"},\"wordCount\":76,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png\",\"keywords\":[\"metabox\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\",\"name\":\"[Solved] Create more Meta Boxes as needed - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png\",\"datePublished\":\"2022-08-21T19:15:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Create more Meta Boxes as needed\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Create more Meta Boxes as needed - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Create more Meta Boxes as needed - JassWeb","og_description":"[ad_1] So you mean something like this? and when you click on Add tracks it becomes this: if it is what you mean the its done by creating a metabox that has simple jquery function to add and remove fields in it, and the data is saved as an array in of data in a ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/","og_site_name":"JassWeb","article_published_time":"2022-08-21T19:15:03+00:00","og_image":[{"url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png","type":"","width":"","height":""}],"author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Create more Meta Boxes as needed","datePublished":"2022-08-21T19:15:03+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/"},"wordCount":76,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png","keywords":["metabox"],"articleSection":["WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/","url":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/","name":"[Solved] Create more Meta Boxes as needed - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png","datePublished":"2022-08-21T19:15:03+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#primaryimage","url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/08\/Solved-Create-more-Meta-Boxes-as-needed.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-create-more-meta-boxes-as-needed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Create more Meta Boxes as needed"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=4230"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4230\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=4230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=4230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=4230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}