From 2717b0193ec200334ff0f545aa6d825aa2c7b6d4 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Mon, 13 Apr 2015 16:41:00 +0100 Subject: [PATCH] Add JSON API. Squashed commit of the following: commit 0b7a6a1d4d07ac0252de39c9f2e9c87e468afe86 Author: Adrian Short Date: Mon Apr 13 15:15:49 2015 +0100 Bump version 0.1.2.1 commit e79c77c68f6cfe763079e7ee8a5b02040d0c5159 Author: Adrian Short Date: Mon Apr 13 14:20:07 2015 +0100 Return all sites commit 7b1079190dc5f57a2ebf781fb8a2cd37c60e359d Author: Adrian Short Date: Mon Apr 13 14:07:17 2015 +0100 Bump version number 0.1.2 commit aa6379760414ac7f33e1418112f1b97c3c546a3c Author: Adrian Short Date: Mon Apr 13 14:02:26 2015 +0100 Add extra fields commit aa5ab1ea1da2fde8407af602b8370b58cbc9d3e4 Author: Adrian Short Date: Mon Apr 13 11:10:04 2015 +0100 Remove function commit 50a18cd31153b779ae2203a59076cfddd95afcfc Author: Adrian Short Date: Thu Apr 9 10:27:21 2015 +0100 Serve JSON feed for sites --- includes/sites.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++ talhyperlocal.php | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 includes/sites.php diff --git a/includes/sites.php b/includes/sites.php new file mode 100644 index 0000000..decdec4 --- /dev/null +++ b/includes/sites.php @@ -0,0 +1,51 @@ + 'site', + 'posts_per_page' => -1, // -1 for all posts + 'post_status' => 'publish', + 'orderby' => 'title', + 'order' => 'ASC' +); + +$query = new WP_Query( $options ) or die("WP Query failed"); + +$sites = array(); + +if ( $query->have_posts() ) : + while ( $query->have_posts() ) : $query->the_post() ; + $meta = get_post_meta( get_the_ID() ); + + // party_affiliation + // hyperlocal_group_id + + $row = array( + 'title' => get_the_title(), + 'url' => get_permalink(), + 'feed_url' => $meta['feed_url'][0], + 'date_created' => get_the_date("c"), + 'date_modified' => get_the_modified_date("c"), + 'lat' => (float)$meta['geo_latitude'][0], + 'lon' => (float)$meta['geo_longitude'][0], + 'radius_miles' => (float)$meta['distance_covered_miles'][0], + 'area_covered' => $meta['area_covered'][0], + 'body' => get_the_content(), + 'area_covered' => $meta['area_covered'][0], + 'country' => get_the_terms( get_the_ID(), 'countries' ), + 'council' => get_the_terms( get_the_ID(), 'councils' ), + 'platform' => get_the_terms( get_the_ID(), 'platforms' ), + ); + + $sites[]= $row; + endwhile; +else : + echo "No posts matched the query"; +endif; + +header( "Content-Type: application/json" ); +echo json_encode( $sites ); diff --git a/talhyperlocal.php b/talhyperlocal.php index b997235..6d79ba7 100644 --- a/talhyperlocal.php +++ b/talhyperlocal.php @@ -3,7 +3,7 @@ Plugin Name: Talk About Local Hyperlocal Sites Directory Plugin URI: Description: -Version: 0.1.1 +Version: 0.1.2.1 Author: Adrian Short Author URI: https://adrianshort.org/ License: GPL v3