1

I'm using WP REST API V2 in my project. After sending Get request to get posts, I don't see fields with the source of my audio/video wordpress posts (youtube or soundcloud sources).

I would like to know how to include source field of (audio and video posts) into my request results. If my post is an audio or video post:

enter image description here

These posts have source field that can be set to soundcloud or youtube track url:

enter image description here enter image description here

I need to get these sources in the results of my get request. I have an idea that it should look similar to getting thumbnail url setting up a function to get a field in functions.php file , but I don't know how to set it and what function with which fields should it be to get source urls of audio and video posts.

P.S. Example of getting thumbnail url function in functions.php file:

add_action( 'rest_api_init', 'ccw_insert_thumbnail_url' );
                function ccw_insert_thumbnail_url() {
                    register_rest_field( 'post',
                        'ccw_thumbnail',
                        array(
                            'get_callback'    => 'ccw_get_thumbnail_url',
                            'update_callback' => null,
                            'schema'          => null,
                        )
                    );
                }

            function ccw_get_thumbnail_url($post){
                if(has_post_thumbnail($post['id'])){
                    $imgArray = wp_get_attachment_image_src( get_post_thumbnail_id( $post['id'] ), 'thumbnail' );
                    $imgURL = $imgArray[0];
                    return $imgURL;
                }else{
                    return false;   
                }
            }
Adelmaer
  • 2,209
  • 3
  • 22
  • 45
  • Possible duplicate of [How do you add custom fields defined in posts to the rest API responses in wordpress](https://stackoverflow.com/questions/43986513/how-do-you-add-custom-fields-defined-in-posts-to-the-rest-api-responses-in-wordp) – Paul Sweatte Jul 12 '17 at 17:11

0 Answers0