REST API中的注册表元数据未显示自定义POST类型元数据

时间:2021-01-10 作者:Alt C

我添加了一个自定义post类型,我想在rest api中公开自定义字段值。根据文档,可以使用register\\u meta。

我用wordpress的方式创建了一个自定义的post meta框。它工作正常,但没有显示在RESTAPI中。我相信我必须通过数组

enter image description here

add_action( \'rest_api_init\', \'qrcode_register_posts_meta_field\' );

function qrcode_register_posts_meta_field(){
  $meta_args = array( // Validate and sanitize the meta value.
    \'type\'         => \'array\',
    
    \'description\'  => \'A meta key associated with a string meta value.\',
   
    \'single\'       => true,
   
    \'show_in_rest\' => array(
      \'schema\'=> array(
        \'type\'=> \'array\',
        \'items\'=> array(
          \'type\'=> \'string\',
        ),
      ),
    ),
);
  register_meta( \'post\', \'qrcode_qr-code-type\', $meta_args );
}

1 个回复
SO网友:Alt C

发现:我忘记为自定义帖子类型启用自定义字段,即使元框是通过编程创建的。