Posts featured image url not showing
-
I am trying to get wordpress post featured image using wordpress rest api plugin. I have try many times. But can not get the url of wordpress post featured image. Here is my code.
<?php
$url = ‘https://localhost/start/wp-json/wp/v2/posts/49’; //get posts
$response = wp_safe_remote_get( $url );
$url_img = ‘https://localhost/start/wp-json/wp/v2/posts/49?filter%5Bfeatured_media%5D=26;’; //get featured image
$response_img = wp_safe_remote_get( $url_img );if ( ! is_wp_error( $response ) ) {
$remote_post = json_decode( wp_remote_retrieve_body( $response ) ); //decode posts
$remote_post_img = json_decode( wp_remote_retrieve_body( $response_img ) ); //decode featured image
var_dump($remote_post_img); //for debugging$images = esc_url($remote_post_img->_links->embeddable->href) ;
?>
<img src=”<?php echo $images ;?>”/>Please help me some way
- The topic ‘Posts featured image url not showing’ is closed to new replies.