File: /var/www/html/www.uscornatese.it/json/topnews.php
<?php
require_once('../wp-load.php' );
global $wpdb;
$maxLastNews = 100;
$sql = "(select * from wp_posts where post_status = 'publish' and id in (select object_id from wp_term_relationships where term_taxonomy_id = 5)) order by post_date desc limit 0, " . $maxLastNews. ";";
$records = $wpdb->get_results($sql);
$values = array();
foreach ( $records as $record ) {
$id = $record->ID;
$content = $record->post_content;
$content = preg_replace( '/(width|height)="\d*"\s/', "", $content );
$content = str_replace("<img ", "<img width=\"300\" ", $content);
$record->post_content = $content;
$date = $record->post_date;
$pdate = explode("-", substr($date, 0, 10));
$post_date = $pdate[2] . "-" . $pdate[1] . "-" . $pdate[0];
$record->post_title = strip_tags(strtolower($record->post_title));
$record->post_date = $post_date . " " . substr($date, 11, 8);
$image = get_the_post_thumbnail_url($id);
// echo $record->post_title . " " . $path . " " . $image . "<br>";
$record->image = $image;
//if ($image != "") {
// $record->image = Img_Resize($image, "570", "thumb");
//}
$values[] = $record;
}
echo json_encode($values);
?>