Skip to content

How to retrieve content from local site to live wordpress site using wp rest api #13

Description

@djouonang

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');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions