{"id":19024900,"date":"2026-09-21T04:24:15","date_gmt":"2026-09-21T04:24:15","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/server-only-block-array-attribute\/"},"modified":"2026-09-21T04:24:15","modified_gmt":"2026-09-21T04:24:15","slug":"server-only-block-array-attribute","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/server-only-block-array-attribute\/","title":{"rendered":"Server-only block array attribute"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have a plugin that registers a simple custom block server-side only using register_block_type(). It works fine, but I&#8217;m looking to add an array attribute to allow the editor to select multiple options. I could do it with multiple boolean attributes, but I thought I&#8217;d try with an array as it&#8217;d be neater in the GUI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So I added the following to the attributes array element:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        'show' =&gt; &#091;\n            'label'   =&gt; 'Information to show',\n            'type'    =&gt; 'array',\n            'items'   =&gt; &#091;\n                'type' =&gt; 'string',\n            ],\n            'enum'    =&gt; &#091;'Price', 'Location', 'Description', 'Status', 'Conditions', 'Contact'],\n            'default' =&gt; &#091;'Price'],\n            'autoGenerateControl' =&gt; true,\n        ],<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that I had to add autoGenerateControl to get the multi-select control to display on the settings bar, after I did that it displayed as expected with the default value correctly loaded.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But if I try to add or remove options using the multi-select control, two things happen:<\/p>\n\n\n\n<ol>\n<li>The post\/page isn&#8217;t marked as &#8220;dirty&#8221; so I can&#8217;t save it, and<\/li>\n\n\n\n<li>The block itself displays &#8220;Error loading block: [object Object]&#8221;<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Note that if I remove all options from the multi-select control, the block displays as expected, it only displays this message if I select one or more options. Even though the render function is not yet coded to use the array attribute at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Is it possible to do this? I&#8217;d really prefer if it can be done with server-side hooks only, as I&#8217;d rather not have to refactor the whole plugin to use npm. Any help appreciated.<\/p>\n","protected":false},"template":"","class_list":["post-19024900","topic","type-topic","status-publish","hentry","topic-tag-array","topic-tag-attribute","topic-tag-block"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19024900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19024900\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19024900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}