not really known
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 9 roky
před 9 roky
před 9 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // ini_set( 'display_errors', 'stdout' );
  3. // error_reporting( E_ALL );
  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' => array( 'publish', 'archive' ),
  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. if ( isset( $meta['feed_url'] ) ) $feed_url = $meta['feed_url'][0];
  21. if ( isset( $meta['area_covered'] ) ) $area_covered = html_entity_decode( $meta['area_covered'][0] );
  22. $row = array(
  23. 'title' => html_entity_decode( get_the_title() ),
  24. 'permalink' => get_permalink(),
  25. 'url' => $meta['url'][0],
  26. 'feed_url' => $feed_url,
  27. 'date_created' => get_the_date("c"),
  28. 'date_modified' => get_the_modified_date("c"),
  29. 'lat' => (float)$meta['geo_latitude'][0],
  30. 'lon' => (float)$meta['geo_longitude'][0],
  31. 'radius_miles' => (float)$meta['distance_covered_miles'][0],
  32. 'area_covered' => $area_covered,
  33. 'body' => get_the_content(),
  34. 'country' => tax_first_name( get_the_ID(), 'countries' ),
  35. 'council' => tax_first_name( get_the_ID(), 'councils' ),
  36. 'platform' => tax_first_name( get_the_ID(), 'platforms' ),
  37. 'group' => tax_first_name( get_the_ID(), 'groups' )
  38. );
  39. $sites[]= $row;
  40. endwhile;
  41. else :
  42. echo "No posts matched the query";
  43. endif;
  44. if ( isset( $_GET['format'] ) && $_GET['format'] == 'csv' ) {
  45. header( "Content-Type: text/csv" );
  46. header('Content-Disposition: attachment; filename="localweblist.csv"');
  47. $fp = fopen('php://output', 'w');
  48. fputcsv( $fp, array(
  49. 'title',
  50. 'permalink',
  51. 'url',
  52. 'feed_url',
  53. 'date_created',
  54. 'date_modified',
  55. 'lat',
  56. 'lon',
  57. 'radius_miles',
  58. 'area_covered',
  59. 'body',
  60. 'country',
  61. 'council',
  62. 'platform',
  63. 'group'
  64. )
  65. );
  66. foreach ( $sites as $row ) {
  67. fputcsv( $fp, $row );
  68. }
  69. fclose($fp);
  70. } else {
  71. header( "Content-Type: application/json" );
  72. echo json_encode( $sites );
  73. }
  74. // Get the name of the first taxonomy term for a given post
  75. function tax_first_name( $id, $tax_name ) {
  76. $terms = get_the_terms( $id, $tax_name );
  77. if ( $terms ) {
  78. $first_term = array_slice( $terms, 0, 1 );
  79. $bare_term = array_shift( $first_term );
  80. $name = $bare_term->name;
  81. return( html_entity_decode( $name ) );
  82. } else {
  83. return null;
  84. }
  85. }