Created
July 8, 2011 18:42
-
-
Save kkestell/1072489 to your computer and use it in GitHub Desktop.
Get WP Posts as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(dirname(__FILE__) . '/wp-load.php'); | |
require_once(dirname(__FILE__) . '/wp-includes/post.php'); | |
$args = array( | |
'numberposts' => 100, | |
'offset' => 0, | |
'orderby' => 'post_date', | |
'order' => 'DESC', | |
'post_type' => 'post', | |
'post_status' => 'publish' | |
); | |
$posts = get_posts($args); | |
$items = array(); | |
foreach($posts as $post) { | |
setup_postdata($post); | |
$item = array(); | |
$item['guid'] = $post->guid; | |
$item['title'] = $post->post_title; | |
$item['content'] = $post->post_excerpt; | |
$tid = get_post_thumbnail_id($post->ID); | |
$thumb = get_post($tid); | |
$item['thumbnail'] = $thumb->guid; | |
if($item['guid'] != $item['thumbnail']) { | |
$items[] = $item; | |
} | |
if(count($items) == 3) break; | |
} | |
echo json_encode($items); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment