WordPress REST API 添加元数据meta

示例:添加wiki元数据

$object_type = 'post';
$meta_args = array( // Validate and sanitize the meta value.
    // Note: currently (4.7) one of 'string', 'boolean', 'integer',
    // 'number' must be used as 'type'. The default is 'string'.
    'type'         => 'string',
    // Shown in the schema for the meta key.
    'description'  => 'A meta key associated with a string meta value.',
    // Return a single value of the type.
    'single'       => true,
    // Show in the WP REST API response. Default: false.
    'show_in_rest' => true,
);
register_meta( $object_type, 'wiki', $meta_args );

配置中show_in_rest默认false,rest-api中设置true才可显示。

元标签功能需开启自定义字段

官方文档:https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/