How would you explain this to a newbie?
eg.: I have two websites, I want one to display the posts of the other through JSON API?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow would you explain this to a newbie?
eg.: I have two websites, I want one to display the posts of the other through JSON API?
I dont know how to edit question, I found this: but this way I cannot specify my requests, is there any way to modify this code so that I can specify it?
function check_api_data() { if(isset($_GET['api']) ) { if ($_GET['api'] == 'json'){ $args = array( 'post_status' => 'publish', 'nopaging' => true, 'orderby' => 'title', 'order' => 'ASC' ); $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) ) ); } echo json_encode( $output ); } exit(); } }