Created
October 4, 2011 23:18
-
-
Save andredublin/1263132 to your computer and use it in GitHub Desktop.
Wordpress loop that assign an associative array to an array then echo 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
define('WP_USE_THEMES', false); | |
require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php'); | |
header('HTTP/1.1 200 OK'); | |
header('Content-type: application/json;'); | |
$posts = array(); | |
if (have_post()) : | |
while (have_posts()) : | |
$posts = the_post(); | |
$posts['id'] = the_ID(); | |
$posts['title'] = the_title(); | |
$results[] = $posts; | |
endwhile; | |
echo json_encode($results); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment