Wp db query show posts from last 3 days only
-
Hi guys and girls
Does anyone know how to amend the wpdb query so it will display the posts from the last 3 days only, for a google news feed..
// Load WordPress configuration
require(“wp.travel.php”);// Fetch options from database
$permalink_structure = $wpdb->get_var(“SELECT option_value FROM $wpdb->options
WHERE option_name=’permalink_structure'”);
$siteurl = $wpdb->get_var(“SELECT option_value FROM $wpdb->options
WHERE option_name=’siteurl'”);// Output XML header
echo “<?xml version=\”1.0\” encoding=\”utf-8\”?>\n”;// Begin urlset
echo “<urlset xmlns=\”https://www.sitemaps.org/schemas/sitemap/0.9\”
xmlns:news=\”https://www.google.com/schemas/sitemap-news/0.9\”>\n”;// Select all posts
$rows = $wpdb->get_results(“SELECT ID, post_date_gmt
FROM $wpdb->posts WHERE post_status=’publish'”);// Output sitemap data
foreach($rows as $row){
echo “\t<url>\n”;
echo “\t\t<loc>”;
echo get_permalink($row->ID);
echo “</loc>\n”;
echo “\t\t<news:news>\n”;
echo “\t\t<news:publication_date>”;
$thedate = substr($row->post_date_gmt, 0, 10);
$thetime = substr($row->post_date_gmt, 11, 20);
echo $thedate . ‘T’ . $thetime . ‘Z’;
echo “</news:publication_date>\n”;
echo “\t\t<news:keywords>computers,internet</news:keywords>\n”; // change these keywords
echo “\t\t</news:news>\n”;
echo “\t</url>\n”;
}// End urlset
echo “</urlset>”;
?>Thanks
Kev
- The topic ‘Wp db query show posts from last 3 days only’ is closed to new replies.