admin管理员组

文章数量:1122846

hi i very new to rest api...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)

im trying use many api like wp-json/wp/v2/media /wp-json/wp/v2/posts?_embed wp-json/wp/v2/posts/?video_url

i dont know how to fix this..pls anyone help me to fix this..

i can able to get only featured image for tat video post..could not able to play video..

hi i very new to rest api...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)

im trying use many api like wp-json/wp/v2/media /wp-json/wp/v2/posts?_embed wp-json/wp/v2/posts/?video_url

i dont know how to fix this..pls anyone help me to fix this..

i can able to get only featured image for tat video post..could not able to play video..

Share Improve this question asked May 18, 2020 at 8:20 Divya MohanDivya Mohan 12 bronze badges 2
  • Is this a custom post type with a video_url field? You'd need to register the field for the REST API. Or a regular post with a YouTube URL in it that gets turned into a player with oEmbeded? – Rup Commented May 18, 2020 at 8:25
  • its a custom post video – Divya Mohan Commented May 18, 2020 at 9:54
Add a comment  | 

1 Answer 1

Reset to default 0

You have a custom post type called 'video' with a video_url field. You need to call register_post_meta in the rest_api_init hook to get the API to return this field, e.g.

function register_post_meta_video_video_url( $wp_rest_server ) {
    register_post_meta( 'video', 'video_url', array(
        'type'         => 'string',
        'description'  => 'Featured video URL',
        'single'       => true,
        'show_in_rest' => true,
    ) );
};
add_action( 'rest_api_init', 'register_post_meta_video_video_url', 10, 1 );

See REST API Modifying Responses.

本文标签: Need wp rest api for featured video post