Hi,
From my own research, I managed to register a new postmeta and output the field to the WP REST API for Posts.
register_rest_field( ‘post’, ‘newPostField’, array(
‘update_callback’ => null,
‘schema’ => null,
‘get_callback’ => function ( $data ) {
return get_post_meta( $data[‘id’], ‘postmeta’, ‘true’ );
}, ));
I tried to do the same to register a new termmeta but unable to get it to work like the above.
register_rest_field( ‘terms’, ‘newTermField’, array( //tried to use ‘post_tag’ instead of ‘terms’ but it don’t work. Suspect the problem is here
‘update_callback’ => null,
‘schema’ => null,
‘get_callback’ => function ( $data ) {
return “test”; //get_term_meta( $data[‘id’], ‘termmeta’, ‘true’ ); //test also don’t show up
}, ));
Appreciate if you can provide advice on this.
Thanks.