I got this code
add_action( 'init', 'check_api_data' ); function check_api_data() { if(isset($_GET['api']) ) { if ($_GET['api'] == 'json'){ $args = array( 'post_type' => 'post' ); $query = new WP_Query( $args ); // $query is the WP_Query Object $posts = $query->get_posts(); // $posts contains the post objects $output = array(); foreach( $posts as $post ) { // Pluck the id and title attributes $output[] = array( 'id' => $post->ID, 'title' => $post->post_title, 'content' => $post ->post_content, 'imageurl' => wp_get_attachment_url( get_post_thumbnail_id($post->ID) ) ); } header("Content-type: application/json"); echo json_encode( $output ); } exit(); } }
This is the output:
[ { "id": 19, "title": "Early bird tickets", "content": "that is good", "imageurl": "http://localhost/PRACTISE/wp/wp-content/uploads/2016/10/news2.jpg" }, { "id": 95, "title": "See you next year!", "content": "Lorem ipsum", "imageurl": "http://localhost/PRACTISE/wp/wp-content/uploads/2016/11/tak_for_i_aar.jpg" } ]
How can I use this data in a remote server, so that everytime I update my content of Server A it gets updated at Server B