块错误:post_axs_obj不是对象的有效属性

时间:2021-11-09 作者:Jon Chubb

我们的一个块已经停止工作,我知道这可能是因为“post\\u taxs\\u obj”没有包含在PHP register\\u block\\u类型属性中,但我不知道如何解决这个问题-请任何人提出建议?(我不是开发人员,只是想加入并修复此问题,因此非常感谢您的帮助):

错误:

{"code":"rest_invalid_param","message":"Invalid parameter(s): attributes","data":{"status":400,"params":{"attributes":"post_taxs_obj is not a valid property of Object."},"details":{"attributes":{"code":"rest_additional_properties_forbidden","message":"post_taxs_obj is not a valid property of Object.","data":null}}}}
以下是PHP:

register_block_type( \'performancein/article-listing\',
        array(
            \'render_callback\' => \'performancein_article_listing_callback\',
            \'attributes\'      => [
                \'post_type\'            => [
                    \'default\' => \'\',
                    \'type\'    => \'string\'
                ],
                \'post_taxs\'            => [
                    \'default\' => \'\',
                    \'type\'    => \'string\'
                ],
                \'post_category\'        => [
                    \'default\' => \'\',
                    \'type\'    => \'string\'
                ],
                \'number_of_post\'       => [
                    \'default\' => \'0\',
                    \'type\'    => \'number\'
                ],
                \'category_description\' => [
                    \'default\' => false,
                    \'type\'    => \'bool\'
                ],
                \'exclude_post\'         => [
                    \'default\' => \'\',
                    \'type\'    => \'string\'
                ],

            ]
        )
    );
和JS:

registerBlockType(\'performancein/article-listing\', {
  title: \'Article Listing\',
  icon: ArticleIcon,
  category: \'performancein\',
  keywords: [__(\'ArticleFilter\'), __(\'gutenberg\'), __(\'performancein\')],
  description: __( \'It showcase article listing \' ),
  example: {
    attributes: {
      caption: __( \'Article Listing\' ),
    },
  },
  attributes: {

    number_of_post: {
      type: \'number\',
      default: \'0\',
    },
    post_type: {
      default: \'\',
      type: \'string\',
    },
    post_type_obj: {
      type: \'json\',
    },
    post_taxs: {
      default: \'\',
      type: \'string\',
    },
    post_taxs_obj: {
      default: [{label: \'--Select Taxonomy--\', value: \'\'}],
      type: \'json\',
    },
    post_category: {
      default: \'\',
      type: \'string\',
    },
    post_category_obj: {
      default: [{label: \'--Select Category--\', value: \'\'}],
      type: \'json\',
    },
    category_description: {
      default: false,
      type: \'boolean\',
    },
    exclude_post: {type: \'string\'},
    design_option: {
      type: \'string\',
      default: \'\',
    },
  },

UPDATE

感谢修复Tom,解决方案只是按照他的指导,采用以下格式:

\'post_type_obj\'        => [
                    \'default\' => \'\',
                    \'type\'    => \'json\'
                ],

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

您的PHP将块注册为6 attributes.

您的JS将块注册到10 attributes.

他们must

您可以:

将缺少的属性添加到PHP中,或从javascript中删除额外的属性,很可能是第一个属性。

另外,您是否考虑过使用服务器端注册block.json 完全回避这个问题?那么你的JS注册只需要3件东西,块名及其编辑/保存组件,其他所有东西都会自动从block.json, WP会将所有数据内联并自动使用。它甚至可以为您将前端和编辑器脚本排队。

相关推荐