not really known
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

81 rader
2.2 KiB

  1. <?php
  2. // ini_set( 'display_errors', 1 );
  3. // error_reporting( E_ALL ^ E_NOTICE );
  4. define( 'WP_USE_THEMES', false );
  5. require_once( '../../../../wp-load.php' );
  6. $options = array(
  7. 'post_type' => 'site',
  8. 'posts_per_page' => -1, // -1 for all posts
  9. 'post_status' => 'publish',
  10. 'orderby' => 'title',
  11. 'order' => 'ASC'
  12. );
  13. $query = new WP_Query( $options ) or die("WP Query failed");
  14. $sites = array();
  15. if ( $query->have_posts() ) :
  16. while ( $query->have_posts() ) : $query->the_post() ;
  17. $meta = get_post_meta( get_the_ID() );
  18. // party_affiliation
  19. // hyperlocal_group_id
  20. $row = array(
  21. 'title' => get_the_title(),
  22. 'permalink' => get_permalink(),
  23. 'url' => $meta['url'][0],
  24. 'feed_url' => $meta['feed_url'][0],
  25. 'date_created' => get_the_date("c"),
  26. 'date_modified' => get_the_modified_date("c"),
  27. 'lat' => (float)$meta['geo_latitude'][0],
  28. 'lon' => (float)$meta['geo_longitude'][0],
  29. 'radius_miles' => (float)$meta['distance_covered_miles'][0],
  30. 'area_covered' => $meta['area_covered'][0],
  31. 'body' => get_the_content(),
  32. 'country' => array_values(get_the_terms( get_the_ID(), 'countries' ))[0]->name,
  33. 'council' => array_values(get_the_terms( get_the_ID(), 'councils' ))[0]->name,
  34. 'platform' => array_values(get_the_terms( get_the_ID(), 'platforms' ))[0]->name,
  35. 'group' => array_values(get_the_terms( get_the_ID(), 'groups' ))[0]->name
  36. );
  37. $sites[]= $row;
  38. endwhile;
  39. else :
  40. echo "No posts matched the query";
  41. endif;
  42. if ( $_GET['format'] == 'csv' ) {
  43. header( "Content-Type: text/csv" );
  44. header('Content-Disposition: attachment; filename="localweblist.csv"');
  45. $fp = fopen('php://output', 'w');
  46. fputcsv( $fp, array(
  47. 'title',
  48. 'permalink',
  49. 'url',
  50. 'feed_url',
  51. 'date_created',
  52. 'date_modified',
  53. 'lat',
  54. 'lon',
  55. 'radius_miles',
  56. 'area_covered',
  57. 'body',
  58. 'country',
  59. 'council',
  60. 'platform',
  61. 'group'
  62. )
  63. );
  64. foreach ( $sites as $row ) {
  65. fputcsv( $fp, $row );
  66. }
  67. fclose($fp);
  68. } else {
  69. header( "Content-Type: application/json" );
  70. echo json_encode( $sites );
  71. }