I want to show tow post meta in one rendered field rest api

my fields are 1- folder_path 2- file_name call example website/folderpath/filename.ext

i want to show it everywhere in rest api

add_action( 'rest_api_init', 'create_api_posts_meta_field' );

function create_api_posts_meta_field() {

 // register_rest_field ( 'name-of-post-type', 'name-of-field-to-return', array-of-callbacks-and-schema() )
 register_rest_field( 'post', 'download_link', array(
 'get_callback' => 'get_post_meta_for_api',
 'schema' => null,

function get_post_meta_for_api( $object ) {
 //get the id of the post object array
 $post_id = $object['id'];

 //return the post meta
 return get_post_meta( $post_id );

wp-json/wp/v2/posts wp-json/wp/v2/search wp-json/wp/v2/posts/ etc..

thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.