微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么Muy自定义Gutenberg块返回空的innerHtml和innerContent字段?

如何解决为什么Muy自定义Gutenberg块返回空的innerHtml和innerContent字段?

我已经在api中公开了这些块:

add_action('rest_api_init',function () {

  if ( ! function_exists( 'use_block_editor_for_post_type' ) ) {

    require ABSPATH . 'wp-admin/includes/post.PHP';
  }

  $post_types = get_post_types_by_support( [ 'editor' ] );

  foreach ( $post_types as $post_type ) {

    if ( use_block_editor_for_post_type( $post_type ) ) {

      register_rest_field($post_type,'blocks',['get_callback' => function ( array $post ) {

        $raw_blocks =  parse_blocks( $post['content']['raw'] );

        $supported_blocks = [];

        foreach ($raw_blocks as $raw_block) {

          if( $raw_block['blockName'] ){

            array_push($supported_blocks,$raw_block);

          }

        }

        return $supported_blocks;

      }]);

    }

  }

});

这样注册我的区块:

function register_acf_block_types() {
  // register a testimonial block.
  acf_register_block_type(array(
     'name'              => 'info-picture','title'             => __('Home Info/Picture Block'),'description'       => __('A custom info/picture block.'),'render_template'   => 'template-parts/blocks/info-picture/info-picture.PHP','category'          => 'common','icon'              => 'admin-comments','keywords'          => array( 'info','picture' ),));
}
// Check if function exists and hook into setup.
if( function_exists('acf_register_block_type') ) {
  add_action('acf/init','register_acf_block_types');
}

但是当我对api:http://my.syte/wp-json/wp/v2/pages/8进行GET调用时,我得到了:

            "innerBlocks": [],"innerHTML": "","innerContent": []

我找不到从这些字段中获取数据的方法

我知道了:

"content": {
  "rendered: "the whole HTML of the page..."
}

但是我需要特定自定义块的innerHtml或innerContent。

非常感谢您!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。