| @@ -26,7 +26,8 @@ if ( $query->have_posts() ) : | |||||
| $row = array( | $row = array( | ||||
| 'title' => get_the_title(), | 'title' => get_the_title(), | ||||
| 'url' => get_permalink(), | |||||
| 'permalink' => get_permalink(), | |||||
| 'url' => $meta['url'][0], | |||||
| 'feed_url' => $meta['feed_url'][0], | 'feed_url' => $meta['feed_url'][0], | ||||
| 'date_created' => get_the_date("c"), | 'date_created' => get_the_date("c"), | ||||
| 'date_modified' => get_the_modified_date("c"), | 'date_modified' => get_the_modified_date("c"), | ||||
| @@ -35,7 +36,6 @@ if ( $query->have_posts() ) : | |||||
| 'radius_miles' => (float)$meta['distance_covered_miles'][0], | 'radius_miles' => (float)$meta['distance_covered_miles'][0], | ||||
| 'area_covered' => $meta['area_covered'][0], | 'area_covered' => $meta['area_covered'][0], | ||||
| 'body' => get_the_content(), | 'body' => get_the_content(), | ||||
| 'area_covered' => $meta['area_covered'][0], | |||||
| 'country' => array_values(get_the_terms( get_the_ID(), 'countries' ))[0]->name, | 'country' => array_values(get_the_terms( get_the_ID(), 'countries' ))[0]->name, | ||||
| 'council' => array_values(get_the_terms( get_the_ID(), 'councils' ))[0]->name, | 'council' => array_values(get_the_terms( get_the_ID(), 'councils' ))[0]->name, | ||||
| 'platform' => array_values(get_the_terms( get_the_ID(), 'platforms' ))[0]->name, | 'platform' => array_values(get_the_terms( get_the_ID(), 'platforms' ))[0]->name, | ||||
| @@ -48,5 +48,33 @@ else : | |||||
| echo "No posts matched the query"; | echo "No posts matched the query"; | ||||
| endif; | endif; | ||||
| header( "Content-Type: application/json" ); | |||||
| echo json_encode( $sites ); | |||||
| if ( $_GET['format'] == 'csv' ) { | |||||
| header( "Content-Type: text/csv" ); | |||||
| header('Content-Disposition: attachment; filename="localweblist.csv"'); | |||||
| $fp = fopen('php://output', 'w'); | |||||
| fputcsv( $fp, array( | |||||
| 'title', | |||||
| 'permalink', | |||||
| 'url', | |||||
| 'feed_url', | |||||
| 'date_created', | |||||
| 'date_modified', | |||||
| 'lat', | |||||
| 'lon', | |||||
| 'radius_miles', | |||||
| 'area_covered', | |||||
| 'body', | |||||
| 'country', | |||||
| 'council', | |||||
| 'platform', | |||||
| 'group' | |||||
| ) | |||||
| ); | |||||
| foreach ( $sites as $row ) { | |||||
| fputcsv( $fp, $row ); | |||||
| } | |||||
| fclose($fp); | |||||
| } else { | |||||
| header( "Content-Type: application/json" ); | |||||
| echo json_encode( $sites ); | |||||
| } | |||||