0

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.. enter image description here

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

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
    May 18 '20 at 8:25
  • its a custom post video May 18 '20 at 9:54
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.

3
  • In which file i needs to add this code.. In funtion.php? May 21 '20 at 17:38
  • Yes, in functions.php in a custom plugin. (Or possibly functions.php in a custom theme too, but I'm not sure the wp-admin site actually loads the theme?)
    – Rup
    May 21 '20 at 23:13
  • Thankq Rup ..i got a solutions for tis...Could u ls help me to get related post, related video post api... May 25 '20 at 5:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.