最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rest api - How to add field to custom post type endpoint

programmeradmin0浏览0评论

I have an endpoint in this address:

example/wp-json/wp/v2/myendpoint

I want to add a field to the endpoint with these codes:

add_action( 'rest_api_init', 'create_api_posts_meta_field' );
 
function create_api_posts_meta_field() {    
    register_rest_field( 
        'myendpoint',
        'post-meta-fields',
        array(
           'get_callback'    => 'get_post_meta_for_api',
        )
    );
}
 
function get_post_meta_for_api( ) {
    $hello="Hello";
    return $hello;
}

but it doesn't work. Please tell me whats wrong with my codes.

发布评论

评论列表(0)

  1. 暂无评论