Hello I have been trying to use the wp rest api to pull data from local site to live wordpress site with use of shortcode. When i try to do the reverse that is to pull posts from live to local it works but when i change links to retrieve from local to live it does not display anything on the page. I already have the wp rest api installed on both sites. Below is my code:
function my_recent_posts_shortcode($atts){
$response = wp_remote_get( 'http://localhost/wordpress/wp-json/wp/v2/posts' );
if( is_wp_error( $response ) ) {
return;
}
$posts = json_decode( wp_remote_retrieve_body( $response ) );
if( empty( $posts ) ) {
return;
}
if( !empty( $posts ) ) {
$list = '';
foreach( $posts as $post ) {
$list .='
link. '">' . $post->title->rendered . '
';
}
return $list . '';
}
}
add_shortcode('recent-posts', 'my_recent_posts_shortcode');
Hello I have been trying to use the wp rest api to pull data from local site to live wordpress site with use of shortcode. When i try to do the reverse that is to pull posts from live to local it works but when i change links to retrieve from local to live it does not display anything on the page. I already have the wp rest api installed on both sites. Below is my code: