Created
October 26, 2012 09:17
-
-
Save emersonbroga/3957794 to your computer and use it in GitHub Desktop.
Json Wordpress Api for UITableView in Objective-C projects
This file contains hidden or 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
function app_api() | |
{ | |
$return = array('status' => 'error', 'status_msg' => 'Operation Error'); | |
$params = $_GET; | |
unset($params['action']); | |
$result = get_posts($params); | |
if($result){ | |
$return['status'] = 'ok'; | |
$return['status_msg'] = 'Opereation Complete'; | |
$return['posts'] = array(); | |
global $post; | |
foreach($result as $post){ | |
setup_postdata( $post ); | |
$array = array(); | |
$array['title'] = html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8'); | |
$array['link'] = html_entity_decode(get_permalink(), ENT_COMPAT, 'UTF-8'); | |
$array['excerpt'] = html_entity_decode(get_the_excerpt(), ENT_COMPAT, 'UTF-8'); | |
$array['date'] = html_entity_decode(get_the_date(), ENT_COMPAT, 'UTF-8'); | |
array_push($return['posts'], $array); | |
} | |
} | |
echo json_encode($return); | |
die(); | |
} | |
add_action('wp_ajax_app_api', 'app_ap'); | |
add_action('wp_ajax_nopriv_app_api', 'app_ap'); | |
//On your objective-c Class, just call | |
// http://www.site.com/wp-admin/admin-ajax.php?action=app_api&post_type=post&posts_per_page=-1 | |
//(or any other wordpress query_post query, don't forget the param action with your function name as a value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment