not really known
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

94 líneas
2.5 KiB

  1. <?php
  2. ini_set( 'display_errors', 1 );
  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' => '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' => html_entity_decode( 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' => html_entity_decode( $meta['area_covered'][0] ),
  31. 'body' => get_the_content(),
  32. 'country' => tax_first_name( get_the_ID(), 'countries' ),
  33. 'council' => tax_first_name( get_the_ID(), 'councils' ),
  34. 'platform' => tax_first_name( get_the_ID(), 'platforms' ),
  35. 'group' => tax_first_name( get_the_ID(), 'groups' )
  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. }
  72. // Get the name of the first taxonomy term for a given post
  73. function tax_first_name( $id, $tax_name ) {
  74. $terms = get_the_terms( $id, $tax_name );
  75. if ( $terms ) {
  76. $first_term = array_slice( $terms, 0, 1 );
  77. $bare_term = array_shift( $first_term );
  78. $name = $bare_term->name;
  79. return( html_entity_decode( $name ) );
  80. } else {
  81. return null;
  82. }
  83. }